window.hpp 2.37 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
/*
 WINDOW.HPP

 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.
*/
#ifndef __window_hpp__

#include "group.hpp"
#include <string.h>
#include <stdlib.h>
#if defined(__WATCOMC__)
#include <malloc.h>
#endif

class window : public group
{

public:

    enum attributes
    {
        EMPTY=                          (1 << 0),
        BORDER=                         (1 << 1),
        TITLE=                          (1 << 2),
        MINMAX=                         (1 << 3),
        RESIZE=                         (1 << 4),
        SYSTEM=                         (1 << 5)
    };
    
    window(
        int const                       i_pos_x,
        int const                       i_pos_y,
        unsigned int const              i_len_x,
        unsigned int const              i_len_y);
    
    virtual
    ~window();
    
    virtual void
    draw() const;

    enum attributes
    get_attributes() const;
    
    unsigned char const*
    get_title() const;

    void
    set_attributes(
        unsigned const                  i_attributes);
    
    void
    set_title(
        unsigned char const*            i_str);

protected:

    unsigned char*                      m_title;
    enum attributes                     m_attributes;

private:

    window();

    window(
    const window&);

    window&
    operator=(window const&);

};

inline window::attributes
window::get_attributes() const
{
    return m_attributes;
}

inline unsigned char const*
window::get_title() const
{
    return m_title;
}

inline void
window::set_attributes(
    unsigned const                      i_attributes)
{
    m_attributes= static_cast<enum attributes>(i_attributes);
    return;
}

inline void
window::set_title(
    unsigned char const*                i_str)
{

    free(m_title);
    m_title= 0;

    if (i_str && i_str[0])
    {
        size_t                          l_len;
        l_len= 1+strlen(reinterpret_cast<char const*>(i_str));
        m_title= reinterpret_cast<unsigned char*>(malloc(l_len));
        if (m_title)
        {
            memcpy(m_title, i_str, l_len);
        }
    }

    return;
}

#define __window_hpp__
#endif