Ticket #537: sellist_fallback_fix.patch

File sellist_fallback_fix.patch, 6.4 KB (added by westram, 11 years ago)

update

  • WINDOW/AW_awar.cxx

     
    699699
    700700    aw_assert(is_valid());
    701701
     702#if defined(TRACE_PROBLEMATIC_AWAR_USAGE)
     703    if (gb_origin != gb_var) {
     704        // detect whether this is mapped to another awar
     705        const char *dbpath = GB_get_db_path(gb_var);
     706
     707        if      (ARB_strBeginsWith(dbpath, "/main/"))     dbpath = dbpath+6;
     708        else if (ARB_strBeginsWith(dbpath, "/<gbmain>/")) dbpath = dbpath+10;
     709
     710        track_awar_mapping(this->get_name(), dbpath);
     711    }
     712#endif
     713
    702714    return this;
    703715}
    704716
  • WINDOW/aw_awar.hxx

     
    166166};
    167167
    168168void AW_awar_dump_changes(const char* name);
     169
     170// --------------------------------------------------------------------------------
     171// see http://bugs.arb-home.de/ticket/520
     172
     173#if defined(DEBUG)
     174#define TRACE_PROBLEMATIC_AWAR_USAGE
     175#endif
     176
     177#if defined(TRACE_PROBLEMATIC_AWAR_USAGE)
     178
     179#include <map>
     180
     181enum UsedInWidget { UIW_SELLIST = 1, UIW_OTHER = 2, UIW_BOTH = 3 };
     182class AW_awar;
     183
     184void track_problematic_awar_usage(AW_awar *awar, UsedInWidget where);
     185void track_awar_mapping(std::string awarname_org, std::string awarname_mappedTo);
     186
     187#endif
  • WINDOW/AW_select.cxx

     
    2727
    2828#include "aw_type_checking.hxx"
    2929
     30#include <map>
     31
     32#if defined(TRACE_PROBLEMATIC_AWAR_USAGE)
     33
     34typedef std::map<std::string, std::string>  AwarMapping;
     35typedef std::map<std::string, UsedInWidget> AwarUsage;
     36
     37static AwarMapping amap;
     38static AwarUsage   usage;
     39
     40static void track_awars_mapped_with(std::string awar_name);
     41static void combine_awar_usage(std::string awar_name1, std::string awar_name2);
     42static void track_problematic_awar_usage_byname(std::string awar_name, UsedInWidget where) {
     43    aw_assert(where != UIW_BOTH);
     44    fprintf(stderr, "track_problematic_awar_usage_byname('%s', %i) [start]\n", awar_name.c_str(), int(where));
     45
     46    AwarUsage::iterator found = usage.find(awar_name);
     47    if (found == usage.end()) {
     48        usage[awar_name] = where;
     49        track_awars_mapped_with(awar_name);
     50    }
     51    else {
     52        if (found->second != where) {
     53            if (found->second != UIW_BOTH) {
     54                // detected problematic use of awar! (used in selection list and in input field)
     55                usage[awar_name] = UIW_BOTH;
     56                aw_assert(0);
     57            }
     58        }
     59    }
     60    fprintf(stderr, "track_problematic_awar_usage_byname('%s', %i) [end]\n", awar_name.c_str(), int(where));
     61}
     62static void combine_awar_usage(std::string awar_name1, std::string awar_name2) {
     63    aw_assert(awar_name1 != awar_name2);
     64
     65    AwarUsage::iterator found1 = usage.find(awar_name1);
     66    AwarUsage::iterator found2 = usage.find(awar_name2);
     67
     68    fprintf(stderr, "combine_awar_usage('%s', '%s') [start]\n", awar_name1.c_str(), awar_name2.c_str());
     69
     70    if (found1 == usage.end()) {
     71        if (found2 == usage.end()) {
     72            ;
     73        }
     74        else { // awar_name2 already tracked
     75            if (found2->second != UIW_BOTH) { // do not warn twice
     76                track_problematic_awar_usage_byname(awar_name1, found2->second);
     77            }
     78        }
     79    }
     80    else {
     81        if (found2 == usage.end()) { // awar_name1 already tracked
     82            if (found1->second != UIW_BOTH) { // do not warn twice
     83                track_problematic_awar_usage_byname(awar_name2, found1->second);
     84            }
     85        }
     86        else { // both already tracked
     87            if (found1->second != found2->second) {
     88                UsedInWidget add1 = UsedInWidget(found2->second & ~found1->second);
     89                UsedInWidget add2 = UsedInWidget(found1->second & ~found2->second);
     90
     91                if (add1>0 && add1 != UIW_BOTH) track_problematic_awar_usage_byname(awar_name1, add1);
     92                if (add2>0 && add2 != UIW_BOTH) track_problematic_awar_usage_byname(awar_name2, add2);
     93            }
     94        }
     95    }
     96    fprintf(stderr, "combine_awar_usage('%s', '%s') [end]\n", awar_name1.c_str(), awar_name2.c_str());
     97}
     98static void combine_awar_usage(AwarMapping::iterator& m) {
     99    combine_awar_usage(m->first, m->second);
     100}
     101
     102static void track_awars_mapped_with(std::string awar_name) {
     103    fprintf(stderr, "track_awars_mapped_with('%s') [start]\n", awar_name.c_str());
     104    for (AwarMapping::iterator i = amap.begin(); i != amap.end(); ++i) {
     105        if (i->first == awar_name || i->second == awar_name) {
     106            combine_awar_usage(i);
     107        }
     108    }
     109    fprintf(stderr, "track_awars_mapped_with('%s') [end]\n", awar_name.c_str());
     110}
     111
     112void track_problematic_awar_usage(AW_awar *awar, UsedInWidget where) {
     113    track_problematic_awar_usage_byname(awar->get_name(), where);
     114}
     115void track_awar_mapping(std::string awarname_org, std::string awarname_mappedTo) {
     116    fprintf(stderr, "track_awar_mapping('%s', '%s') [start]\n", awarname_org.c_str(), awarname_mappedTo.c_str());
     117    amap[awarname_org] = awarname_mappedTo;
     118    combine_awar_usage(awarname_org, awarname_mappedTo);
     119    fprintf(stderr, "track_awar_mapping('%s', '%s') [end]\n", awarname_org.c_str(), awarname_mappedTo.c_str());
     120}
     121
     122#endif
     123
    30124static void aw_selection_list_awar_changed(AW_root*, AW_selection_list* slist) {
    31125    slist->refresh();
    32126}
     
    60154{
    61155    aw_assert(NULL != awar);
    62156    awar->add_callback(makeRootCallback(aw_selection_list_awar_changed, this));
     157
     158#if defined(TRACE_PROBLEMATIC_AWAR_USAGE)
     159    if (fallback2default) {
     160        track_problematic_awar_usage(awar, UIW_SELLIST);
     161    }
     162#endif
    63163}
    64164
    65165AW_selection_list::~AW_selection_list() {
  • WINDOW/AW_window.cxx

     
    582582void AW_window::create_input_field(const char *var_name,   int columns) {
    583583    AW_awar* awar = get_root()->awar_no_error(var_name);
    584584    aw_return_if_fail(awar != NULL);
    585    
     585
     586#if defined(TRACE_PROBLEMATIC_AWAR_USAGE)
     587    track_problematic_awar_usage(awar, UIW_OTHER);
     588#endif
     589
    586590    GtkWidget *entry;
    587591
    588592    int width = columns ? columns : _at.length_of_buttons;