Subversion Repositories Filer-Free

Rev

Blame | Last modification | View Log | RSS feed

// This file is part of the free Filer module for RISC OS.
// Copyright © 2007 Graham Shaw.
// Redistribution and modification are permitted under the terms of the
// GNU General Public License (version 2 or any later version).

#include "oslib/fileraction.h"

#include "access_dbox.h"
#include "filer_window.h"

access_dbox::attr_spec access_dbox::attr_icons[attr_count]={
        {fileswitch_ATTR_OWNER_LOCKED,icon_owner_lock_yes,icon_owner_lock_no},
        {fileswitch_ATTR_OWNER_READ,icon_owner_read_yes,icon_owner_read_no},
        {fileswitch_ATTR_OWNER_WRITE,icon_owner_write_yes,icon_owner_write_no},
        {fileswitch_ATTR_WORLD_READ,icon_world_read_yes,icon_world_read_no},
        {fileswitch_ATTR_WORLD_WRITE,icon_world_write_yes,icon_world_write_no}};

access_dbox::access_dbox(application* app):
        template_window(app,"faccess"),
        _owner(0)
{}

void access_dbox::handle_mouse_click(wimp_pointer& block)
{
        if (!_owner)
        {
                return;
        }
        else if (block.i==icon_ok)
        {
                // Begin with the assumption that no attributes are changed.
                int attr_bits=0;
                int attr_mask=0xffff;

                // For each attribute determine whether either of the buttons
                // is selected, and adjust the attribute masks accordingly.
                wimp_icon_state state;
                for (unsigned int i=0;i!=attr_count;++i)
                {
                        state.i=attr_icons[i].icon_yes;
                        get_icon_state(state);
                        if (state.icon.flags&wimp_ICON_SELECTED)
                        {
                                // If yes button selected then set attribute to one.
                                attr_bits|=attr_icons[i].attr;
                                attr_mask&=~attr_icons[i].attr;
                        }
                        state.i=attr_icons[i].icon_no;
                        get_icon_state(state);
                        if (state.icon.flags&wimp_ICON_SELECTED)
                        {
                                // If no button selected then set attribute to zero.
                                attr_bits&=~attr_icons[i].attr;
                                attr_mask&=~attr_icons[i].attr;
                        }
                }

                // Get filer action flags from filer window options.
                fileraction_flags flags=_owner->options().flags();

                // Set the recurse flag iff the recurse button is selected.
                state.i=icon_recurse;
                get_icon_state(state);
                if (state.icon.flags&wimp_ICON_SELECTED)
                {
                        flags|=fileraction_RECURSE;
                }

                // Apply attributes to filer window selection.
                int attr=attr_bits|(attr_mask<<16);
                wimp_t handle=_owner->begin_filer_action();
                xfileractionsendstartoperation_access(handle,flags,&attr);
        }
        else if (block.i==icon_recurse)
        {
                // Toggle recurse icon.
                set_icon_state(icon_recurse,wimp_ICON_SELECTED,0);
        }
}

void access_dbox::owner(filer_window* owner)
{
        _owner=owner;
}

void access_dbox::update(osgbpb_info* info)
{
        // For each pair of radio buttons.
        for (unsigned int i=0;i!=attr_count;++i)
        {
                if (info)
                {
                        // If an object has been specified then set the radio buttons
                        // to match that object.
                        int icon_off=attr_icons[i].icon_yes;
                        int icon_on=attr_icons[i].icon_no;

                        if (info->attr&attr_icons[i].attr)
                        {
                                int temp=icon_off;
                                icon_off=icon_on;
                                icon_on=temp;
                        }
                        set_icon_state(icon_off,0,wimp_ICON_SELECTED);
                        set_icon_state(icon_on,wimp_ICON_SELECTED,wimp_ICON_SELECTED);
                }
                else
                {
                        // If no object was specified then unset both radio buttons.
                        set_icon_state(attr_icons[i].icon_yes,0,wimp_ICON_SELECTED);
                        set_icon_state(attr_icons[i].icon_no,0,wimp_ICON_SELECTED);
                }
        }

        // The recurse button is always selected by default.
        set_icon_state(icon_recurse,wimp_ICON_SELECTED,wimp_ICON_SELECTED);

        // The recurse button is enabled when a directory (or image file)
        // is selected, or when more than one object is selected (whether
        // or not the selection includes any directories).
        set_icon_state(icon_recurse,
                (!info||(info->obj_type&fileswitch_IS_DIR))?0:wimp_ICON_SHADED,
                wimp_ICON_SHADED);
}