radiobtn.cpp 2.58 KB
Newer Older
Ercan Ersoy's avatar
Ercan Ersoy committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143
/*
 RADIOBTN.CPP

 License CC0 PUBLIC DOMAIN

 To the extent possible under law, Mark J. Olesen has waived all copyright 
 and related or neighboring rights to FDOSTUI Library. This work is published 
 from: United States.
*/
#include "radiobtn.hpp"

radiobutton::radiobutton(
    int const                           i_pos_x,
    int const                           i_pos_y,
    unsigned int const                  i_len_x,
    unsigned int const                  i_len_y) :
    checkbutton(i_pos_x, i_pos_y, i_len_x, i_len_y),
    m_next(0),
    m_prev(0)
{
    m_type= TYPE_RADIO;
    return;
}
    
radiobutton::~radiobutton()
{
    return;
}

void
radiobutton::toggled()
{
#if defined(__CURSES__)
    int                                 l_cur_x;
    int                                 l_cur_y;
#endif
    radiobutton*                        l_btn;

#if defined(__CURSES__)
    if (0 == (CURSOR_CAN_HIDE & _cursor_features))
    {
        getyx(stdscr, l_cur_y, l_cur_x);
    }
#endif

    do
    {

        l_btn= m_prev;

        do
        {

            if (0 == l_btn)
            {
                break;
            }

            (*l_btn).clear_state();

            l_btn= (*l_btn).m_prev;

        }while(1);

        l_btn= m_next;

        do
        {

            if (0 == l_btn)
            {
                break;
            }

            (*l_btn).clear_state();

            l_btn= (*l_btn).m_next;

        }while(1);

    }while(0);

#if defined(__CURSES__)
    if (0 == (CURSOR_CAN_HIDE & _cursor_features))
    {
        ::move(l_cur_y, l_cur_x);
    }
#endif

    return;
}

bool
radiobutton::join(
    radiobutton*const                   i_radiobutton)
{
    bool                                l_joined;
    radiobutton*                        l_tail;

    l_joined= false;

    do
    {

        if (this == i_radiobutton)
        {
            break;
        }

        if ((*i_radiobutton).m_next || (*i_radiobutton).m_prev)
        {
            break;
        }

        if (0 == m_next)
        {
            m_next= i_radiobutton;
            (*i_radiobutton).m_prev= this;
            break;
        }

        l_tail= m_next;

        do
        {

            if (0 == (*l_tail).m_next)
            {
                (*l_tail).m_next= i_radiobutton;
                (*i_radiobutton).m_prev= l_tail;
                break;
            }

            l_tail= (*l_tail).m_next;

        }while(1);

        l_joined= 1;

    }while(0);

    return l_joined;
}