<commit_before>/*
 * ion/ionws/split.c
 *
 * Copyright (c) <NAME> 1999-2004. 
 *
 * Ion is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 2.1 of the License, or
 * (at your option) any later version.
 */

#include <limits.h>
#include <string.h>
#include <X11/Xmd.h>

#include <libtu/minmax.h>
#include <libtu/objp.h>
#include <ioncore/common.h>
#include <ioncore/focus.h>
#include <ioncore/global.h>
#include <ioncore/window.h>
#include <ioncore/resize.h>
#include <ioncore/attach.h>
#include <ioncore/defer.h>
#include <ioncore/reginfo.h>
#include <ioncore/extlconv.h>
#include <ioncore/manage.h>
#include <ioncore/region-iter.h>
#include "ionws.h"
#include "split.h"
#include "bindmaps.h"

    
IMPLCLASS(WWsSplit, Obj, NULL, NULL);


/*{{{ Misc helper functions */


static int reg_size(WRegion *reg, int dir)
{
    if(dir==HORIZONTAL)
        return REGION_GEOM(reg).w;
    return REGION_GEOM(reg).h;
}


static int reg_other_size(WRegion *reg, int dir)
{
    if(dir==HORIZONTAL)
        return REGION_GEOM(reg).h;
    return REGION_GEOM(reg).w;
}


static int reg_pos(WRegion *reg, int dir)
{
    if(dir==HORIZONTAL)
        return REGION_GEOM(reg).x;
    return REGION_GEOM(reg).y;
}


static WRectangle split_tree_geom(Obj *obj)
{
    if(OBJ_IS(obj, WRegion))
        return REGION_GEOM(obj);
    
    return ((WWsSplit*)obj)->geom;
}


int split_tree_size(Obj *obj, int dir)
{
    if(OBJ_IS(obj, WRegion))
        return reg_size((WRegion*)obj, dir);
    
    if(dir==HORIZONTAL)
        return ((WWsSplit*)obj)->geom.w;
    return ((WWsSplit*)obj)->geom.h;
}


int split_tree_pos(Obj *obj, int dir)
{
    if(OBJ_IS(obj, WRegion))
        return reg_pos((WRegion*)obj, dir);
    
    if(dir==HORIZONTAL)
        return ((WWsSplit*)obj)->geom.x;
    return ((WWsSplit*)obj)->geom.y;
}


int split_tree_other_size(Obj *obj, int dir)
{
    if(OBJ_IS(obj, WRegion))
        return reg_other_size((WRegion*)obj, dir);
    
    if(dir==HORIZONTAL)
        return ((WWsSplit*)obj)->geom.h;
    return ((WWsSplit*)obj)->geom.w;
}


static int reg_calcresize(WRegion *reg, int dir, int nsize)
{
    int tmp;
    
    if(dir==HORIZONTAL)
        tmp=region_min_w(reg);
    else
        tmp=region_min_h(reg);

    return (nsize<tmp ? tmp : nsize);
}


static int reg_resize(WRegion *reg, int dir, int npos, int nsize)
{
    WRectangle geom=REGION_GEOM(reg);
    
    if(dir==VERTICAL){
        geom.y=npos;
        geom.h=nsize;
        /*wwin->flags&=~WWINDOW_HFORCED;*/
    }else{
        geom.x=npos;
        geom.w=nsize;
        /*wwin->flags&=~WWINDOW_WFORCED;*/
    }
    
    region_fit(reg, &geom);
    
    return nsize;
}


static WWsSplit *split_of_reg(WRegion *reg)
{
    WWsSplit *split=NULL;
    WIonWS *ws=REGION_MANAGER_CHK(reg, WIonWS);
    assert(ws!=NULL);
    extl_table_get(ws->managed_splits, 'o', 'o', reg, &split);
    return split;
}

    
WWsSplit *split_of(Obj *obj)
{
    if(OBJ_IS(obj, WWsSplit)){
        return ((WWsSplit*)obj)->parent;
    }else{
        assert(OBJ_IS(obj, WRegion));
        return split_of_reg((WRegion*)obj);
    }
}


void set_split_of_reg(WRegion *reg, WWsSplit *split)
{
    WIonWS *ws=REGION_MANAGER_CHK(reg, WIonWS);
    assert(ws!=NULL);
    extl_table_set(ws->managed_splits, 'o', 'o', reg, split);
}


void set_split_of(Obj *obj, WWsSplit *split)
{
    if(OBJ_IS(obj, WWsSplit)){
        ((WWsSplit*)obj)->parent=split;
    }else{
        assert(OBJ_IS(obj, WRegion));
        set_split_of_reg((WRegion*)obj, split);
    }
}


/* No, these are not even supposed to be proper/consistent 
 * Z \cup {\infty, -\infty} calculation rules. 
 */
<commit_msg>trunk: changeset 1371<commit_after>/*
 * ion/ionws/split.c
 *
 * Copyright (c) <NAME> 1999-2004. 
 *
 * Ion is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 2.1 of the License, or
 * (at your option) any later version.
 */

#include <limits.h>
#include <string.h>
#include <X11/Xmd.h>

#include <libtu/minmax.h>
#include <libtu/rb.h>
#include <libtu/objp.h>
#include <ioncore/common.h>
#include <ioncore/focus.h>
#include <ioncore/global.h>
#include <ioncore/window.h>
#include <ioncore/resize.h>
#include <ioncore/attach.h>
#include <ioncore/defer.h>
#include <ioncore/reginfo.h>
#include <ioncore/extlconv.h>
#include <ioncore/manage.h>
#include <ioncore/region-iter.h>
#include "ionws.h"
#include "split.h"
#include "bindmaps.h"

    
IMPLCLASS(WWsSplit, Obj, NULL, NULL);


static Rb_node split_of_map=NULL;


/*{{{ Misc helper functions */


static int reg_size(WRegion *reg, int dir)
{
    if(dir==HORIZONTAL)
        return REGION_GEOM(reg).w;
    return REGION_GEOM(reg).h;
}


static int reg_other_size(WRegion *reg, int dir)
{
    if(dir==HORIZONTAL)
        return REGION_GEOM(reg).h;
    return REGION_GEOM(reg).w;
}


static int reg_pos(WRegion *reg, int dir)
{
    if(dir==HORIZONTAL)
        return REGION_GEOM(reg).x;
    return REGION_GEOM(reg).y;
}


static WRectangle split_tree_geom(Obj *obj)
{
    if(OBJ_IS(obj, WRegion))
        return REGION_GEOM(obj);
    
    return ((WWsSplit*)obj)->geom;
}


int split_tree_size(Obj *obj, int dir)
{
    if(OBJ_IS(obj, WRegion))
        return reg_size((WRegion*)obj, dir);
    
    if(dir==HORIZONTAL)
        return ((WWsSplit*)obj)->geom.w;
    return ((WWsSplit*)obj)->geom.h;
}


int split_tree_pos(Obj *obj, int dir)
{
    if(OBJ_IS(obj, WRegion))
        return reg_pos((WRegion*)obj, dir);
    
    if(dir==HORIZONTAL)
        return ((WWsSplit*)obj)->geom.x;
    return ((WWsSplit*)obj)->geom.y;
}


int split_tree_other_size(Obj *obj, int dir)
{
    if(OBJ_IS(obj, WRegion))
        return reg_other_size((WRegion*)obj, dir);
    
    if(dir==HORIZONTAL)
        return ((WWsSplit*)obj)->geom.h;
    return ((WWsSplit*)obj)->geom.w;
}


static int reg_calcresize(WRegion *reg, int dir, int nsize)
{
    int tmp;
    
    if(dir==HORIZONTAL)
        tmp=region_min_w(reg);
    else
        tmp=region_min_h(reg);

    return (nsize<tmp ? tmp : nsize);
}


static int reg_resize(WRegion *reg, int dir, int npos, int nsize)
{
    WRectangle geom=REGION_GEOM(reg);
    
    if(dir==VERTICAL){
        geom.y=npos;
        geom.h=nsize;
        /*wwin->flags&=~WWINDOW_HFORCED;*/
    }else{
        geom.x=npos;
        geom.w=nsize;
        /*wwin->flags&=~WWINDOW_WFORCED;*/
    }
    
    region_fit(reg, &geom);
    
    return nsize;
}


static WWsSplit *split_of_reg(WRegion *reg)
{
    Rb_node node=NULL;
    int found=0;
    
    assert(REGION_MANAGER_CHK(reg, WIonWS)!=NULL);
    
    if(split_of_map!=NULL){
        node=rb_find_pkey_n(split_of_map, reg, &found);
        if(found)
            return (WWsSplit*)(node->v.val);
    }
    
    return NULL;
}

    
WWsSplit *split_of(Obj *obj)
{
    if(OBJ_IS(obj, WWsSplit)){
        return ((WWsSplit*)obj)->parent;
    }else{
        assert(OBJ_IS(obj, WRegion));
        return split_of_reg((WRegion*)obj);
    }
}


bool set_split_of_reg(WRegion *reg, WWsSplit *split)
{
    Rb_node node=NULL;
    int found;
    
    assert(REGION_MANAGER_CHK(reg, WIonWS)!=NULL);

    if(split_of_map==NULL){
        if(split==NULL)
            return TRUE;
        split_of_map=make_rb();
        if(split_of_map==NULL){
            warn_err();
            return FALSE;
        }
    }
    
    node=rb_find_pkey_n(split_of_map, reg, &found);
    if(found)
        rb_delete_node(node);

    return (rb_insertp(split_of_map, reg, split)!=NULL);
}


void set_split_of(Obj *obj, WWsSplit *split)
{
    if(OBJ_IS(obj, WWsSplit)){
        ((WWsSplit*)obj)->parent=split;
    }else{
        assert(OBJ_IS(obj, WRegion));
        set_split_of_reg((WRegion*)obj, split);
    }
}


/* No, these are not even supposed to be proper/consistent 
 * Z \cup {\infty, -\infty} calculation rules. 
 */

{'fraction_non_alphanumeric': 0.1487468671679198, 'fraction_numerical': 0.0036340852130325816, 'mean_word_length': 3.107565620174987, 'pattern_counts': {'":': 0, '<': 40, '<?xml version=': 0, '>': 63, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4065642', 'n_tokens_mistral': 3223, 'n_tokens_neox': 3123, 'n_words': 610}