PrevNextUpHome SophiaFramework UNIVERSE 5.3
SFOTableCellToggleReactor
Class which provides the check box functions of table cells.
#include <SFOTableCellToggleReactor.h.hpp>
class SFOTableCellToggleReactor : public SFOTableCellReactor;
SFMTYPEDEFREFOBJECT(SFOTableCellToggleReactor)
        

Inheritance diagram

 Inheritance diagram of SFOTableCellToggleReactorClass

Collaboration diagram

 Collaboration diagram of SFOTableCellToggleReactorClass

Description

The SFOTableCellToggleReactor class is a table cell reactor which provides the check box functions to cells whose object type are Bool.

To toggle the checkmark state of a selected table cell, the SFLPROP_EDITABLE property value is to be set to true.

Reference

SFOTableCellReactor | SFXHierarchyProperty

Member

Constructor/Destructor
SFOTableCellToggleReactor( Void )
Constructor of the SFOTableCellToggleReactor class.
~SFOTableCellToggleReactor( Void )
Destructor of the SFOTableCellToggleReactor class.
Public Functions
static
SFOTableCellToggleReactorSmp
NewInstance( SFCErrorPtr exception = null )
Create a new instance of this class.
ValueRec GetProperty( UInt32 key , BoolPtr found = null , Bool recursive = true ) (inherits from SFOTableCellReactor)
Get the property value corresponding to the specified key.
Bool HasProperty( UInt32 key , Bool recursive = true ) (inherits from SFOTableCellReactor)
Check if the specified key is contained.
SFCError SetProperty( UInt32 key , ValueRec value ) (inherits from SFOTableCellReactor)
Set the property value corresponding to the specified key.
Protected Functions
Bool Handle( SFXAnyRef object , SInt32 row )
Toggle the checkmark state of a selected table cell.
SFCError Initialize( Void )
Make the initialization which may raise an error.
Void Render( SFXGraphicsPtr graphics , SFXRectangleConstRef bound , SFXAnyConstRef object , SInt32 row , Bool active , Bool focus )
Draw a check box in a table cell.
static
SFXRectangle
Align( SFXRectangleConstRef src , SFXRectangleConstRef ref , UInt32 alignment ) (inherits from SFOTableCellReactor)
Align the specified rectangle with the base rectangle.
static
SFORefObjectSmp
Factory( SFORefObjectPtr object , SFCErrorPtr exception ) (inherits from SFORefObject)
This function is used to implement the NewInstance function.
UInt32 GetAlignment( Void ) (inherits from SFOTableCellReactor)
Get the alignment.
SFXMargin GetMargin( Void ) (inherits from SFOTableCellReactor)
Get the margin between the table cell area and the cell drawing area.
Void InvokeResultCell( Void ) (inherits from SFOTableCellReactor)
Notify that selecting a table cell is performed.
Bool IsEditable( Void ) (inherits from SFOTableCellReactor)
Check if the cell reactor is editable.
Bool IsWidgetAttachable( Void ) (inherits from SFOTableCellReactor)
Checks if the cell is widget-attachable.
Void OffFocus( SInt32 row , SFYWidgetSmpPtr widget ) (inherits from SFOTableCellReactor)
Handle a table cell which has been unfocused.
Void OnFocus( SFXRectangleConstRef bound , SFXAnyConstRef object , SInt32 row , SFYWidgetSmpPtr widget ) (inherits from SFOTableCellReactor)
Handle a table cell which has been focused.

SFOTableCellToggleReactor::SFOTableCellToggleReactor
Constructor of the SFOTableCellToggleReactor class.
[ protected, explicit ]
SFOTableCellToggleReactor(Void);

Description

This constructor does nothing.


SFOTableCellToggleReactor::~SFOTableCellToggleReactor
Destructor of the SFOTableCellToggleReactor class.
[ protected, virtual ]
~SFOTableCellToggleReactor(Void);

Description

This destructor does nothing.


SFOTableCellToggleReactor::Handle
Toggle the checkmark state of a selected table cell.
[ protected, virtual ]
Bool Handle(
    SFXAnyRef object   // cell object
    SInt32 row         // row index of a selected table cell
);

Return value

  • If the boolean value is changed: true
  • Otherwiser: false

Description

This function toggles the checkmark state of a selected table cell in edit mode.

In the end of the function, the SFOTableCellReactor::InvokeResultCell function is called.

Internal implementation

Internal implementation of this function is as follows.

/*protected virtual */Bool SFOTableCellToggleReactor::Handle(SFXAnyRef object, SInt32 row)
{
    BoolRef                                     toggle(*any_cast<Bool>(&object));
    Bool                                        editable;

    unused(row);
    editable = IsEditable();
    if (editable) {
        toggle = !toggle;
    }
    InvokeResultCell();
    return editable;
}// SFOTableCellToggleReactor::Handle //

Reference

SFOTableCellReactor::InvokeResultCell


SFOTableCellToggleReactor::Initialize
Make the initialization which may raise an error.
[ protected, virtual ]
SFCError Initialize(Void);

Return value

  • If succeeds: SFERR_NO_ERROR
  • If insuffcient memory: SFERR_NO_MEMOERY

Description

This function makes the initialization which may raise an error.

In default, the SFLPROP_LEFTTOP_MARGIN_SIZE property (left top margin size) and the SFLPROP_RIGHTBOTTOM_MARGIN_SIZE property (right bottom margin size) are set to (1, 1).

[Note] Note

This function is called by the SFORefObject::Factory function.

If a concrete class specific initialization code may raise an error, you must override this function.

This function calls the parent Initialize() function first.

Internal implementation

Internal implementation of this function is as follows.

/*protected */SFCError SFOTableCellToggleReactor::Initialize(Void)
{
    static SFXSize::AtomRecConst                MARGINSIZE = {
        1, 1
    };
    SFCError                                    error;

    if ((error = SFOTableCellReactor::Initialize()) == SFERR_NO_ERROR) {
        if ((error = SetProperty(SFLPROP_LEFTTOP_MARGIN_SIZE, MARGINSIZE)) == SFERR_NO_ERROR) {
            error = SetProperty(SFLPROP_RIGHTBOTTOM_MARGIN_SIZE, MARGINSIZE);
        }
    }
    return error;
}// SFOTableCellToggleReactor::Initialize //

Reference

SFORefObject::Factory | SFOTableCellReactor::GetMargin


SFOTableCellToggleReactor::NewInstance
Create a new instance of this class.
[ public, static ]
SFOTableCellToggleReactorSmp NewInstance(
    SFCErrorPtr exception = null   // error value
);

Argument

exception

Return the error value generated inside the function.

Return value

  • If succeeds: not null pointer
  • Otherwise: null pointer

Description

This function creates a new instance of the SFOTableCellToggleReactor class.

If succeeds, a not null pointer will be returned, and the "exception" argument is SFERR_NO_ERROR. If fails, a null pointer will be returned, and the "exception" argument holds the error value.

Example

The following is a code to generate a new instance of the SFOTableCellToggleReactor class.

SFOTableCellReactorSmp rtor;
SFCError error;

if ((rtor = SFOTableCellToggleReactor::NewInstance(&error)) != null) {

    // Set editable
    rtor->SetProperty(SFLPROP_EDITABLE, true);

    // .. (omitted) ..
}

Reference

SFOTableCellToggleReactor


SFOTableCellToggleReactor::Render
Draw a check box in a table cell.
[ protected, virtual, const ]
Void Render(
    SFXGraphicsPtr graphics      // graphics oject
    SFXRectangleConstRef bound   // table cell area
    SFXAnyConstRef object        // cell object
    SInt32 row                   // row index of cell to draw
    Bool active                  // active state of cell
    Bool focus                   // focus state of cell
);

Description

This function draws a check box in a table cell area with considering the margin and the alignment.

The appearance is the same as the SFZCheckboxControl class.

Internal implementation

Internal implementation of this function is as follows.

/*protected virtual */Void SFOTableCellToggleReactor::Render(SFXGraphicsPtr graphics, SFXRectangleConstRef bound, SFXAnyConstRef object, SInt32 row, Bool active, Bool focus) const
{
    SFXRectangle                                rxCB;
    SFXRectangle                                content;
    SFXRectangle                                clip;
    SFXGrid                                     grid;
    Bool                                        press(false);
    Bool                                        checked(any_cast<Bool>(object));

    unused(row);
    clip.Set(graphics->GetClip());
    content.Set(SFXRectangle(bound).Deflate(GetMargin()));
    graphics->SetClip(SFXRectangle(content).Intersection(clip));
    if (content.GetHeight() >= 28) {
        rxCB.SetWidth(28).SetHeight(28);
        rxCB.Set(Align(rxCB, content, GetAlignment()));
        grid.Set(DrawShadow28(graphics, rxCB.GetOrigin(), active, press));
        DrawButton27(graphics, grid, active, focus, press);
        grid.Add(3, 3);
        DrawCheckmark21(graphics, grid, checked, active);
    }
    else if (content.GetHeight() >= 14) {
        rxCB.SetWidth(14).SetHeight(14);
        rxCB.Set(Align(rxCB, content, GetAlignment()));
        grid.Set(DrawShadow14(graphics, rxCB.GetOrigin(), active, press));
        DrawButton13(graphics, grid, active, focus, press);
        grid.Add(2, 2);
        DrawCheckmark09(graphics, grid, checked, active);
    }
    graphics->SetClip(clip);
    return;
}// SFOTableCellToggleReactor::Render //

/*protected */Void SFOTableCellToggleReactor::DrawCheckmark09(SFXGraphicsPtr graphics, SFXGridConstRef grid, Bool checked, Bool active) const
{
    static SFXLine::AtomRecConst                line[] = {
        {{ 0,  5}, { 2,  7}},
        {{ 3,  6}, { 8,  1}},
        {{ 0,  6}, { 2,  8}},
        {{ 3,  7}, { 8,  2}}
    };

    RenderCheckmark(graphics, grid, atomic_cast(line), checked, active);
    return;
}// SFOTableCellToggleReactor::DrawCheckmark09 //

/*protected */Void SFOTableCellToggleReactor::DrawCheckmark21(SFXGraphicsPtr graphics, SFXGridConstRef grid, Bool checked, Bool active) const
{
    static SFXLine::AtomRecConst                line[] = {
        {{ 0, 15}, { 4, 19}},
        {{ 5, 18}, {20,  3}},
        {{ 0, 16}, { 4, 20}},
        {{ 5, 19}, {20,  4}}
    };

    RenderCheckmark(graphics, grid, atomic_cast(line), checked, active);
    return;
}// SFOTableCellToggleReactor::DrawCheckmark21 //

/*protected */Void SFOTableCellToggleReactor::DrawButton13(SFXGraphicsPtr graphics, SFXGridConstRef grid, Bool active, Bool focus, Bool press) const
{
    static SFXRectangle::AtomRecConst           rectangle[] = {
        {{ 0,  0}, {13, 13}},
        {{ 2,  2}, { 9,  9}}
    };

    RenderButton(graphics, grid, atomic_cast(rectangle), active, focus, press);
    return;
}// SFOTableCellToggleReactor::DrawButton13 //

/*protected */Void SFOTableCellToggleReactor::DrawButton27(SFXGraphicsPtr graphics, SFXGridConstRef grid, Bool active, Bool focus, Bool press) const
{
    static SFXRectangle::AtomRecConst           rectangle[] = {
        {{ 0,  0}, {27, 27}},
        {{ 2,  2}, {23, 23}}
    };

    RenderButton(graphics, grid, atomic_cast(rectangle), active, focus, press);
    return;
}// SFOTableCellToggleReactor::DrawButton27 //

/*protected */SFXGrid SFOTableCellToggleReactor::DrawShadow14(SFXGraphicsPtr graphics, SFXGridConstRef grid, Bool active, Bool press) const
{
    static SFXLine::AtomRecConst                line[][2] = {
        {{{13,  0}, {13, 13}}, {{ 0, 13}, {13, 13}}},
        {{{ 0,  0}, {13,  0}}, {{ 0,  0}, { 0, 13}}}
    };
    SFXGrid                                     result(grid);

    if (press) {
        RenderShadow(graphics, grid, atomic_cast(line[1]), active);
        result.Add(1, 1);
    }
    else {
        RenderShadow(graphics, grid, atomic_cast(line[0]), active);
        result.Add(0, 0);
    }
    return result;
}// SFOTableCellToggleReactor::DrawShadow14 //

/*protected */SFXGrid SFOTableCellToggleReactor::DrawShadow28(SFXGraphicsPtr graphics, SFXGridConstRef grid, Bool active, Bool press) const
{
    static SFXLine::AtomRecConst                line[][2] = {
        {{{27,  0}, {27, 27}}, {{ 0, 27}, {27, 27}}},
        {{{ 0,  0}, {27,  0}}, {{ 0,  0}, { 0, 27}}}
    };
    SFXGrid                                     result(grid);

    if (press) {
        RenderShadow(graphics, grid, atomic_cast(line[1]), active);
        result.Add(1, 1);
    }
    else {
        RenderShadow(graphics, grid, atomic_cast(line[0]), active);
        result.Add(0, 0);
    }
    return result;
}// SFOTableCellToggleReactor::DrawShadow28 //

/*private */Void SFOTableCellToggleReactor::RenderCheckmark(SFXGraphicsPtr graphics, SFXGridConstRef grid, SFXLineConst line[4], Bool checked, Bool active) const
{
    SFXRGBColor                                 rgb;
    SFXRGBColor                                 checkmark(0x00, 0x00, 0x00, 0x00);
    Bool                                        checkmarkBright;

    if (checked) {
        graphics->SetTranslate(-grid);
        rgb.Set(checkmark);
        checkmarkBright = checkmark.GetBrightness() > 0x7F;
        if (!active) {
            (checkmarkBright) ? rgb.SubRGB(0x44) : rgb.AddRGB(0x44);
        }
        graphics->SetForeColor(rgb);
        graphics->DrawLine(line[0]);
        graphics->DrawLine(line[1]);
        (checkmarkBright) ? rgb.SubRGB(0x44) : rgb.AddRGB(0x44);
        graphics->SetForeColor(rgb);
        graphics->DrawLine(line[2]);
        graphics->DrawLine(line[3]);
        graphics->SetTranslate(grid);
    }
    return;
}// SFOTableCellToggleReactor::RenderCheckmark //

/*private */Void SFOTableCellToggleReactor::RenderButton(SFXGraphicsPtr graphics, SFXGridConstRef grid, SFXRectangleConst rectangle[2], Bool active, Bool focus, Bool press) const
{
    SFXBevelColor                               bevel;
    SFXRGBColorConstRef                         base(GetButtonColor().GetBase());
    SFXRGBColor                                 rgb;

    graphics->SetTranslate(-grid);
    bevel.Set(focus ? (GetFocusColor()) : (GetButtonColor()));
    rgb.Set(base);
    if (!active) {
        bevel.SetLight(bevel.GetBase());
        bevel.SetDark(bevel.GetBase());
    }
    if (press) {
        if (base.GetBrightness() > 0x7F) {
            bevel.SubRGB(0x11);
            rgb.SubRGB(0x11);
        }
        else {
            bevel.AddRGB(0x11);
            rgb.AddRGB(0x11);
        }
    }
    graphics->FillBevelRectangle(rectangle[0], bevel);
    graphics->FillRectangle(rectangle[1], rgb);
    graphics->SetTranslate(grid);
    return;
}// SFOTableCellToggleReactor::RenderButton //

/*private */Void SFOTableCellToggleReactor::RenderShadow(SFXGraphicsPtr graphics, SFXGridConstRef grid, SFXLineConst line[2], Bool active) const
{
    SFXRGBColor                                 rgb;

    graphics->SetTranslate(-grid);
    rgb.Set(GetShadowColor());
    if (!active) {
        (rgb.GetBrightness() > 0x7F) ? rgb.SubRGB(0x44) : rgb.AddRGB(0x44);
    }
    graphics->SetForeColor(rgb);
    graphics->DrawLine(line[0]);
    graphics->DrawLine(line[1]);
    graphics->SetTranslate(grid);
    return;
}// SFOTableCellToggleReactor::RenderShadow //

/*private static */SFXBevelColorConstRef SFOTableCellToggleReactor::GetFocusColor(Void)
{
    static SFXBevelColor::AtomRecConst          bevel = {
        {{{0x00, 0xCC, 0xCC, 0xCC}}}, {{{0x00, 0xAA, 0xAA, 0xAA}}}, {{{0x00, 0x55, 0x55, 0x55}}}
    };
    return bevel;
}// SFOTableCellToggleReactor::GetFocusColor //

/*private static */SFXBevelColorConstRef SFOTableCellToggleReactor::GetButtonColor(Void)
{
    static SFXBevelColor::AtomRecConst          bevel = {
        {{{0x00, 0xFF, 0xFF, 0xFF}}}, {{{0x00, 0xDD, 0xDD, 0xDD}}}, {{{0x00, 0x88, 0x88, 0x88}}}
    };
    return bevel;
}// SFOTableCellToggleReactor::GetButtonColor //

/*private static */SFXRGBColorConstRef SFOTableCellToggleReactor::GetShadowColor(Void)
{
    static SFXRGBColor::AtomRecConst            rgb = {
        {{0x00, 0x00, 0x00, 0x00}}
    };
    return rgb;
}// SFOTableCellToggleReactor::GetShadowColor //

Reference

SFZCheckboxControl::HandleRenderRequest