diff options
author | Steve Hart <libreoffice@stevehart.net> | 2015-11-17 15:23:39 +0200 |
---|---|---|
committer | Maxim Monastirsky <momonasmon@gmail.com> | 2015-11-17 16:19:20 +0200 |
commit | 1b9956c2b150c37cf0e695f88bc0394f41d130a2 (patch) | |
tree | c4650b385c88df935ad109a60bf442e02d32e861 | |
parent | 703f3f452b470687bdc3041abe4f3d75230ac8c1 (diff) |
tdf#34882 Adding hex and decimal code search
Change-Id: I809bac4b28e679c7dad8ed3ad28e36379bce4760
-rw-r--r-- | cui/source/dialogs/cuicharmap.cxx | 62 | ||||
-rw-r--r-- | cui/source/inc/cuicharmap.hxx | 7 | ||||
-rw-r--r-- | cui/uiconfig/ui/specialcharacters.ui | 105 | ||||
-rw-r--r-- | extras/source/glade/libreoffice-catalog.xml.in | 3 |
4 files changed, 159 insertions, 18 deletions
diff --git a/cui/source/dialogs/cuicharmap.cxx b/cui/source/dialogs/cuicharmap.cxx index bbf06a90fcd7..62346d850cea 100644 --- a/cui/source/dialogs/cuicharmap.cxx +++ b/cui/source/dialogs/cuicharmap.cxx @@ -63,9 +63,10 @@ SvxCharacterMap::SvxCharacterMap( vcl::Window* pParent, bool bOne_, const SfxIte //lock the size request of this widget to the width of all possible entries fillAllSubsets(*m_pSubsetLB); m_pSubsetLB->set_width_request(m_pSubsetLB->get_preferred_size().Width()); - get(m_pCharCodeText, "charcodeft"); + get(m_pHexCodeText, "hexvalue"); + get(m_pDecimalCodeText, "decimalvalue"); //lock the size request of this widget to the width of the original .ui string - m_pCharCodeText->set_width_request(m_pCharCodeText->get_preferred_size().Width()); + m_pHexCodeText->set_width_request(m_pHexCodeText->get_preferred_size().Width()); get(m_pSymbolText, "symboltext"); const SfxBoolItem* pItem = SfxItemSet::GetItem<SfxBoolItem>(pSet, FN_PARAM_1, false); @@ -117,7 +118,8 @@ void SvxCharacterMap::dispose() m_pSubsetLB.clear(); m_pSymbolText.clear(); m_pShowChar.clear(); - m_pCharCodeText.clear(); + m_pHexCodeText.clear(); + m_pDecimalCodeText.clear(); SfxModalDialog::dispose(); } @@ -368,6 +370,8 @@ void SvxCharacterMap::init() m_pShowSet->SetSelectHdl( LINK( this, SvxCharacterMap, CharSelectHdl ) ); m_pShowSet->SetHighlightHdl( LINK( this, SvxCharacterMap, CharHighlightHdl ) ); m_pShowSet->SetPreSelectHdl( LINK( this, SvxCharacterMap, CharPreSelectHdl ) ); + m_pDecimalCodeText->SetModifyHdl( LINK( this, SvxCharacterMap, DecimalCodeChangeHdl ) ); + m_pHexCodeText->SetModifyHdl( LINK( this, SvxCharacterMap, HexCodeChangeHdl ) ); if( SvxShowCharSet::getSelectedChar() == ' ') m_pOKBtn->Disable(); @@ -538,6 +542,8 @@ IMPL_LINK_NOARG_TYPED(SvxCharacterMap, CharSelectHdl, SvxShowCharSet*, void) IMPL_LINK_NOARG_TYPED(SvxCharacterMap, CharHighlightHdl, SvxShowCharSet*, void) { OUString aText; + OUString aHexText; + OUString aDecimalText; sal_UCS4 cChar = m_pShowSet->GetSelectCharacter(); bool bSelect = (cChar > 0); @@ -558,19 +564,57 @@ IMPL_LINK_NOARG_TYPED(SvxCharacterMap, CharHighlightHdl, SvxShowCharSet*, void) m_pShowChar->SetText( aText ); m_pShowChar->Update(); - // show char code + // show char codes if ( bSelect ) { + // Get the hexadecimal code char aBuf[32]; - snprintf( aBuf, sizeof(aBuf), "U+%04X", static_cast<unsigned>(cChar) ); - if( cChar < 0x0100 ) - snprintf( aBuf+6, sizeof(aBuf)-6, " (%u)", static_cast<unsigned>(cChar) ); - aText = OUString::createFromAscii(aBuf); + snprintf( aBuf, sizeof(aBuf), "%X", static_cast<unsigned>(cChar) ); + aHexText = OUString::createFromAscii(aBuf); + // Get the decimal code + char aDecBuf[32]; + snprintf( aDecBuf, sizeof(aDecBuf), "%u", static_cast<unsigned>(cChar) ); + aDecimalText = OUString::createFromAscii(aDecBuf); } - m_pCharCodeText->SetText( aText ); + + // Update the hex and decimal codes only if necessary + if (m_pHexCodeText->GetText() != aHexText) + m_pHexCodeText->SetText( aHexText ); + if (m_pDecimalCodeText->GetText() != aDecimalText) + m_pDecimalCodeText->SetText( aDecimalText ); +} + +void SvxCharacterMap::selectCharByCode(Radix radix) +{ + OUString aCodeString; + switch(radix) + { + case Radix::decimal: + aCodeString = m_pDecimalCodeText->GetText(); + break; + case Radix::hexadecimal: + aCodeString = m_pHexCodeText->GetText(); + break; + } + // Convert the code back to a character using the appropriate radix + sal_UCS4 cChar = aCodeString.toUInt32(static_cast<sal_Int16> (radix)); + // Use FontCharMap::HasChar(sal_UCS4 cChar) to see if the desired character is in the font + FontCharMapPtr pFontCharMap(new FontCharMap()); + m_pShowSet->GetFontCharMap(pFontCharMap); + if (pFontCharMap->HasChar(cChar)) + // Select the corresponding character + SetChar(cChar); } +IMPL_LINK_NOARG_TYPED(SvxCharacterMap, DecimalCodeChangeHdl, Edit&, void) +{ + selectCharByCode(Radix::decimal); +} +IMPL_LINK_NOARG_TYPED(SvxCharacterMap, HexCodeChangeHdl, Edit&, void) +{ + selectCharByCode(Radix::hexadecimal); +} IMPL_LINK_NOARG_TYPED(SvxCharacterMap, CharPreSelectHdl, SvxShowCharSet*, void) { diff --git a/cui/source/inc/cuicharmap.hxx b/cui/source/inc/cuicharmap.hxx index 869df9f25488..9e1efa9ff1a2 100644 --- a/cui/source/inc/cuicharmap.hxx +++ b/cui/source/inc/cuicharmap.hxx @@ -76,10 +76,12 @@ private: VclPtr<ListBox> m_pSubsetLB; VclPtr<FixedText> m_pSymbolText; VclPtr<SvxShowText> m_pShowChar; - VclPtr<FixedText> m_pCharCodeText; + VclPtr<Edit> m_pHexCodeText; + VclPtr<Edit> m_pDecimalCodeText; vcl::Font aFont; bool bOne; const SubsetMap* pSubsetMap; + enum class Radix : sal_Int16 {decimal = 10, hexadecimal=16}; DECL_LINK_TYPED(OKHdl, Button*, void); DECL_LINK_TYPED(FontSelectHdl, ListBox&, void); @@ -88,8 +90,11 @@ private: DECL_LINK_TYPED(CharSelectHdl, SvxShowCharSet*, void); DECL_LINK_TYPED(CharHighlightHdl, SvxShowCharSet*, void); DECL_LINK_TYPED(CharPreSelectHdl, SvxShowCharSet*, void); + DECL_LINK_TYPED(DecimalCodeChangeHdl, Edit&, void); + DECL_LINK_TYPED(HexCodeChangeHdl, Edit&, void); static void fillAllSubsets(ListBox &rListBox); + void selectCharByCode(Radix radix); public: SvxCharacterMap( vcl::Window* pParent, bool bOne=true, const SfxItemSet* pSet=nullptr ); diff --git a/cui/uiconfig/ui/specialcharacters.ui b/cui/uiconfig/ui/specialcharacters.ui index f7356ab31b1c..d5b8bd6da54e 100644 --- a/cui/uiconfig/ui/specialcharacters.ui +++ b/cui/uiconfig/ui/specialcharacters.ui @@ -199,24 +199,113 @@ <property name="vexpand">True</property> <child> <object class="cuilo-SvxShowText" id="showchar"> - <property name="width_request">80</property> - <property name="height_request">150</property> + <property name="width_request">80</property> + <property name="height_request">150</property> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="hexpand">True</property> + <property name="vexpand">True</property> + </object> + <packing> + <property name="left_attach">0</property> + <property name="top_attach">0</property> + </packing> + </child> + <child> + <object class="GtkBox" id="box1"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="orientation">vertical</property> + <child> + <object class="GtkLabel" id="decimallabel"> <property name="visible">True</property> <property name="can_focus">False</property> - <property name="hexpand">True</property> - <property name="vexpand">True</property> + <property name="label" translatable="yes">Decimal:</property> </object> + <packing> + <property name="expand">False</property> + <property name="fill">True</property> + <property name="position">0</property> + </packing> + </child> + <child> + <object class="GtkEntry" id="decimalvalue"> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="text">162</property> + <property name="halign">center</property> + <property name="width_chars">11</property> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">True</property> + <property name="position">1</property> + </packing> + </child> + </object> <packing> <property name="left_attach">0</property> - <property name="top_attach">0</property> + <property name="top_attach">2</property> </packing> </child> <child> - <object class="GtkLabel" id="charcodeft"> + <object class="GtkBox" id="box3"> <property name="visible">True</property> <property name="can_focus">False</property> - <property name="hexpand">True</property> - <property name="label" translatable="no"> U+FFFF(65535) </property> + <property name="orientation">vertical</property> + <child> + <object class="GtkLabel" id="hexlabel"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="label" translatable="yes">Hexadecimal:</property> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">True</property> + <property name="position">0</property> + </packing> + </child> + <child> + <object class="GtkGrid" id="grid4"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="halign">center</property> + <child> + <object class="GtkLabel" id="hexulabel"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="label">U+</property> + <property name="selectable">True</property> + <property name="width_chars">3</property> + <property name="single_line_mode">True</property> + <property name="max_width_chars">3</property> + <property name="lines">1</property> + </object> + <packing> + <property name="left_attach">0</property> + <property name="top_attach">0</property> + </packing> + </child> + <child> + <object class="GtkEntry" id="hexvalue"> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="text">A2</property> + <property name="halign">center</property> + <property name="width_chars">8</property> + </object> + <packing> + <property name="left_attach">1</property> + <property name="top_attach">0</property> + </packing> + </child> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">True</property> + <property name="position">1</property> + </packing> + </child> </object> <packing> <property name="left_attach">0</property> diff --git a/extras/source/glade/libreoffice-catalog.xml.in b/extras/source/glade/libreoffice-catalog.xml.in index ea8f688f37a1..58732b1fee4e 100644 --- a/extras/source/glade/libreoffice-catalog.xml.in +++ b/extras/source/glade/libreoffice-catalog.xml.in @@ -804,5 +804,8 @@ <glade-widget-class title="Ruby RadioButton" name="cuilo-RubyRadioButton" generic-name="RubyRadioButton" parent="GtkRadioButton" icon-name="widget-gtk-radiobutton"/> + <glade-widget-class title="Show Text" name="cuilo-SvxShowText" + generic-name="ShowText" parent="GtkDrawingArea" + icon-name="widget-gtk-drawingarea"/> </glade-widget-classes> </glade-catalog> |