1 #include "CUILinkTextBlock.h"
2 
3 #include "../util/VarText.h"
4 #include "CUIControls.h"
5 
CUILinkTextBlock(const std::string & str,const std::shared_ptr<GG::Font> & font,GG::Flags<GG::TextFormat> format,const GG::Clr & color,GG::Flags<GG::WndFlag> flags)6 CUILinkTextBlock::CUILinkTextBlock(const std::string& str, const std::shared_ptr<GG::Font>& font,
7                                    GG::Flags<GG::TextFormat> format, const GG::Clr& color,
8                                    GG::Flags<GG::WndFlag> flags) :
9     GG::BlockControl(GG::X0, GG::Y0, GG::X1, flags | GG::INTERACTIVE),
10     m_link_text(GG::Wnd::Create<CUILinkTextMultiEdit>(str, GG::MULTI_WORDBREAK | GG::MULTI_READ_ONLY | GG::MULTI_LEFT |
11                                                       GG::MULTI_LINEWRAP | GG::MULTI_TOP | GG::MULTI_NO_HSCROLL |
12                                                       GG::MULTI_NO_VSCROLL))
13 {}
14 
CompleteConstruction()15 void CUILinkTextBlock::CompleteConstruction() {
16     GG::BlockControl::CompleteConstruction();
17 
18     AttachChild(m_link_text);
19 
20     m_link_text->SetColor(GG::CLR_ZERO);
21     m_link_text->SetInteriorColor(GG::CLR_ZERO);
22 }
23 
SetMaxWidth(GG::X width)24 GG::Pt CUILinkTextBlock::SetMaxWidth(GG::X width) {
25     m_link_text->Resize(GG::Pt(width, GG::Y1));
26     // Resize to have enough place to show the whole text.
27     GG::Pt size = m_link_text->FullSize();
28 
29     // Only resize when changed.
30     if (size != m_link_text->Size())
31         m_link_text->Resize(size);
32 
33     if (size != Size())
34         Resize(size);
35 
36     return size;
37 }
38 
Text()39 CUILinkTextMultiEdit& CUILinkTextBlock::Text()
40 { return *m_link_text; }
41 
CreateFromTag(const std::string & tag,const GG::RichText::TAG_PARAMS & params,const std::string & content,const std::shared_ptr<GG::Font> & font,const GG::Clr & color,GG::Flags<GG::TextFormat> format)42 std::shared_ptr<GG::BlockControl> CUILinkTextBlock::Factory::CreateFromTag(const std::string& tag,
43                                                                            const GG::RichText::TAG_PARAMS& params,
44                                                                            const std::string& content,
45                                                                            const std::shared_ptr<GG::Font>& font,
46                                                                            const GG::Clr& color,
47                                                                            GG::Flags<GG::TextFormat> format)
48 {
49     auto block = GG::Wnd::Create<CUILinkTextBlock>(content, font, format, color, GG::NO_WND_FLAGS);
50 
51     // Wire the block's signals to come through us.
52     block->m_link_text->LinkClickedSignal.connect(
53         this->LinkClickedSignal);
54     block->m_link_text->LinkDoubleClickedSignal.connect(
55         this->LinkDoubleClickedSignal);
56     block->m_link_text->LinkRightClickedSignal.connect(
57         this->LinkRightClickedSignal);
58 
59     // Color ships and planets by their owner empires.
60     block->m_link_text->SetDecorator(VarText::SHIP_ID_TAG, new ColorByOwner());
61     block->m_link_text->SetDecorator(VarText::PLANET_ID_TAG, new ColorByOwner());
62     block->m_link_text->SetDecorator(TextLinker::BROWSE_PATH_TAG, new PathTypeDecorator());
63 
64     return block;
65 }
66