<commit_before>/*
    Copyright 2005-2007 Adobe Systems Incorporated
    Distributed under the MIT License (see accompanying file LICENSE_1_0_0.txt
    or a copy at http://stlab.adobe.com/licenses.html)
*/

/****************************************************************************************************/

#include <GG/adobe/future/widgets/headers/display.hpp>
#include <GG/adobe/future/widgets/headers/widget_utils.hpp>
#include <GG/adobe/future/widgets/headers/platform_metrics.hpp>
#include <GG/adobe/future/widgets/headers/platform_popup.hpp>
#include <GG/adobe/future/widgets/headers/platform_widget_utils.hpp>
#include <GG/adobe/placeable_concept.hpp>

#include <GG/DropDownList.h>
#include <GG/GUI.h>
#include <GG/StyleFactory.h>
#include <GG/TextControl.h>


/****************************************************************************************************/

namespace {

/****************************************************************************************************/

GG::Y RowHeight()
{
    static GG::Y retval = GG::Y0;
    if (!retval) {
        const GG::Y DEFAULT_MARGIN(8); // DEFAULT_ROW_HEIGHT from ListBox.cpp, minus the default font's lineskip of 14
        retval = adobe::implementation::DefaultFont()->Lineskip() + DEFAULT_MARGIN;
    }
    return retval;
}

/****************************************************************************************************/

GG::Y DropHeight(unsigned int lines)
{ return RowHeight() * static_cast<int>(lines) + static_cast<int>(2 * GG::ListBox::BORDER_THICK); }

/****************************************************************************************************/

enum metrics {
    gap = 4 // Measured as space from popup to label.
};

/****************************************************************************************************/

void clear_menu_items(adobe::popup_t& control)
{
    assert(control.control_m);
    control.menu_items_m.clear();
    control.control_m->Clear();
}

/****************************************************************************************************/

void sel_changed_slot(adobe::popup_t& popup, GG::DropDownList::iterator it)
{
    assert(popup.control_m);

    if (!popup.value_proc_m.empty() || !popup.extended_value_proc_m.empty())
    {
        std::size_t new_index(popup.control_m->CurrentItemIndex());

        if (popup.custom_m)
            --new_index;

        if (popup.value_proc_m)
            popup.value_proc_m(popup.menu_items_m.at(new_index).second);

        if (popup.extended_value_proc_m)
            popup.extended_value_proc_m(popup.menu_items_m.at(new_index).second, adobe::modifier_state());
    }
}

/****************************************************************************************************/

void set_menu_item_set(adobe::popup_t& p, const adobe::popup_t::menu_item_t* first, const adobe::popup_t::menu_item_t* last)
{
    p.custom_m = false;

    unsigned int lines = 0;
    for (; first != last; ++first, ++lines)
    {
        // MM: Revisit. Is there a way to have disabled separators in combo boxes?
        // Since I don't know a way I intercept -'s here. (Dashes inidcate separators
        // on the macintosh and also in eve at the moment).

        if (first->first != "-" && first->first != "__separator") 
            p.menu_items_m.push_back(*first);
    }

    if (p.control_m)
        p.control_m->SetDropHeight(DropHeight(lines));
}

/****************************************************************************************************/

void message_menu_item_set(adobe::popup_t& popup)
{
    assert(popup.control_m);

    for (adobe::popup_t::menu_item_set_t::const_iterator
             first = popup.menu_items_m.begin(), last = popup.menu_items_m.end();
         first != last;
         ++first) {
        GG::ListBox::Row* row = new GG::ListBox::Row(GG::X1, RowHeight(), "");
        row->push_back(adobe::implementation::Factory().NewTextControl(GG::X0, GG::Y0, first->first,
                                                                       adobe::implementation::DefaultFont(),
                                                                       GG::CLR_BLACK, GG::FORMAT_LEFT));
        popup.control_m->Insert(row);
    }

    popup.enable(!popup.menu_items_m.empty());

    if (popup.menu_items_m.empty())
        return;

    popup.display(popup.last_m);
}

/****************************************************************************************************/

} // namespace

/****************************************************************************************************/

namespace adobe {

/****************************************************************************************************/

popup_t::popup_t(const std::string& name,
                 const std::string& alt_text,
                 const std::string& custom_item_name,
                 const menu_item_t* first,
                 const menu_item_t* last,
                 theme_t            theme) :
    control_m(0),
    theme_m(theme),
    name_m(name, alt_text, 0, GG::FORMAT_NONE, theme),
    alt_text_m(alt_text),
    using_label_m(!name.empty()),
    custom_m(false),
    custom_item_name_m(custom_item_name)
{
    ::set_menu_item_set(*this, first, last);
}

/****************************************************************************************************/

void popup_t::measure(extents_t& result)
{
    assert(control_m);

    //
    // The popup_t has multiple text items. We need to find the one with
    // the widest extents (when drawn). Then we can make sure that we get
    // enough space to draw our largest text item.
    //
    const boost::shared_ptr<GG::Font>& font = implementation::DefaultFont();

    menu_item_set_t::iterator first(menu_items_m.begin());
    menu_item_set_t::iterator last(menu_items_m.end());
    GG::Pt largest_extent;
    bool have_extents = false;
    for (; first != last; ++first)
    {
        GG::Pt extent = font->TextExtent(first->first) + GG::Pt(2 * implementation::CharWidth(), GG::Y0);
        if (largest_extent.x < extent.x)
            largest_extent = extent;
        have_extents = true;
    }

    GG::Pt non_client_size = implementation::NonClientSize(*control_m);

    result.width() = Value(largest_extent.x + non_client_size.x);
    result.height() = original_height_m;
    GG::Y baseline =
        (static_cast<int>(result.height()) - implementation::CharHeight()) / 2 +
        implementation::DefaultFont()->Ascent();
    result.vertical().guide_set_m.push_back(Value(baseline));
<commit_msg>Adjusted spacing inside popups in Eve layout tests.<commit_after>/*
    Copyright 2005-2007 Adobe Systems Incorporated
    Distributed under the MIT License (see accompanying file LICENSE_1_0_0.txt
    or a copy at http://stlab.adobe.com/licenses.html)
*/

/****************************************************************************************************/

#include <GG/adobe/future/widgets/headers/display.hpp>
#include <GG/adobe/future/widgets/headers/widget_utils.hpp>
#include <GG/adobe/future/widgets/headers/platform_metrics.hpp>
#include <GG/adobe/future/widgets/headers/platform_popup.hpp>
#include <GG/adobe/future/widgets/headers/platform_widget_utils.hpp>
#include <GG/adobe/placeable_concept.hpp>

#include <GG/DropDownList.h>
#include <GG/GUI.h>
#include <GG/StyleFactory.h>
#include <GG/TextControl.h>


/****************************************************************************************************/

namespace {

/****************************************************************************************************/

GG::Y RowHeight()
{
    static GG::Y retval = GG::Y0;
    if (!retval) {
        const GG::Y DEFAULT_MARGIN(8); // DEFAULT_ROW_HEIGHT from ListBox.cpp, minus the default font's lineskip of 14
        retval = adobe::implementation::DefaultFont()->Lineskip() + DEFAULT_MARGIN;
    }
    return retval;
}

/****************************************************************************************************/

GG::Y DropHeight(unsigned int lines)
{ return RowHeight() * static_cast<int>(lines) + static_cast<int>(2 * GG::ListBox::BORDER_THICK); }

/****************************************************************************************************/

enum metrics {
    gap = 4 // Measured as space from popup to label.
};

/****************************************************************************************************/

void clear_menu_items(adobe::popup_t& control)
{
    assert(control.control_m);
    control.menu_items_m.clear();
    control.control_m->Clear();
}

/****************************************************************************************************/

void sel_changed_slot(adobe::popup_t& popup, GG::DropDownList::iterator it)
{
    assert(popup.control_m);

    if (!popup.value_proc_m.empty() || !popup.extended_value_proc_m.empty())
    {
        std::size_t new_index(popup.control_m->CurrentItemIndex());

        if (popup.custom_m)
            --new_index;

        if (popup.value_proc_m)
            popup.value_proc_m(popup.menu_items_m.at(new_index).second);

        if (popup.extended_value_proc_m)
            popup.extended_value_proc_m(popup.menu_items_m.at(new_index).second, adobe::modifier_state());
    }
}

/****************************************************************************************************/

void set_menu_item_set(adobe::popup_t& p, const adobe::popup_t::menu_item_t* first, const adobe::popup_t::menu_item_t* last)
{
    p.custom_m = false;

    unsigned int lines = 0;
    for (; first != last; ++first, ++lines)
    {
        // MM: Revisit. Is there a way to have disabled separators in combo boxes?
        // Since I don't know a way I intercept -'s here. (Dashes inidcate separators
        // on the macintosh and also in eve at the moment).

        if (first->first != "-" && first->first != "__separator") 
            p.menu_items_m.push_back(*first);
    }

    if (p.control_m)
        p.control_m->SetDropHeight(DropHeight(lines));
}

/****************************************************************************************************/

void message_menu_item_set(adobe::popup_t& popup)
{
    assert(popup.control_m);

    for (adobe::popup_t::menu_item_set_t::const_iterator
             first = popup.menu_items_m.begin(), last = popup.menu_items_m.end();
         first != last;
         ++first) {
        GG::ListBox::Row* row = new GG::ListBox::Row(GG::X1, RowHeight(), "");
        row->push_back(adobe::implementation::Factory().NewTextControl(GG::X0, GG::Y0, first->first,
                                                                       adobe::implementation::DefaultFont(),
                                                                       GG::CLR_BLACK, GG::FORMAT_LEFT));
        popup.control_m->Insert(row);
    }

    popup.enable(!popup.menu_items_m.empty());

    if (popup.menu_items_m.empty())
        return;

    popup.display(popup.last_m);
}

/****************************************************************************************************/

} // namespace

/****************************************************************************************************/

namespace adobe {

/****************************************************************************************************/

popup_t::popup_t(const std::string& name,
                 const std::string& alt_text,
                 const std::string& custom_item_name,
                 const menu_item_t* first,
                 const menu_item_t* last,
                 theme_t            theme) :
    control_m(0),
    theme_m(theme),
    name_m(name, alt_text, 0, GG::FORMAT_NONE, theme),
    alt_text_m(alt_text),
    using_label_m(!name.empty()),
    custom_m(false),
    custom_item_name_m(custom_item_name)
{
    ::set_menu_item_set(*this, first, last);
}

/****************************************************************************************************/

void popup_t::measure(extents_t& result)
{
    assert(control_m);

    //
    // The popup_t has multiple text items. We need to find the one with
    // the widest extents (when drawn). Then we can make sure that we get
    // enough space to draw our largest text item.
    //
    const boost::shared_ptr<GG::Font>& font = implementation::DefaultFont();

    menu_item_set_t::iterator first(menu_items_m.begin());
    menu_item_set_t::iterator last(menu_items_m.end());
    GG::Pt largest_extent;
    bool have_extents = false;
    for (; first != last; ++first)
    {
        GG::Pt extent = font->TextExtent(first->first) + GG::Pt(implementation::CharWidth(), GG::Y0);
        if (largest_extent.x < extent.x)
            largest_extent = extent;
        have_extents = true;
    }

    GG::Pt non_client_size = implementation::NonClientSize(*control_m);

    result.width() = Value(largest_extent.x + non_client_size.x);
    result.height() = original_height_m;
    GG::Y baseline =
        (static_cast<int>(result.height()) - implementation::CharHeight()) / 2 +
        implementation::DefaultFont()->Ascent();
    result.vertical().guide_set_m.push_back(Value(baseline));

{'fraction_non_alphanumeric': 0.3082787010214972, 'fraction_numerical': 0.0038877877725262996, 'mean_word_length': 3.8570899666790077, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 55, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6196984', 'n_tokens_mistral': 3824, 'n_tokens_neox': 3537, 'n_words': 656}