Subversion Repositories Filer-Free


Rev 58 | Blame | Compare with Previous | 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 "directory.h"
#include "pathname_table.h"
#include "auto_pos.h"
#include "window.h"
#include "filer_options.h"

class filer_menu;
class filer_application;

/** A class to represent a filer window. */
class filer_window:
        public window
        friend class filer_application;
        /** The pathname of the directory to be viewed by the filer window. */
        char* _pathname;

        /** The options applicable to this window. */
        filer_options _options;

        /** The content of the directory. */
        directory _directory;

        /** The width of one cell. */
        int _xcsize;

        /** The height of one cell. */
        int _ycsize;

        /** The number of columns. */
        int _xccount;

        /** The number of rows. */
        int _yccount;

        /** The index of the cell temporarily selected while a menu is open,
         * or directory::npos if none. */

        directory::size_type _temp_selection;

        /** The position at which a filer window for a subdirectory will be
         * opened. */

        auto_pos _auto_pos;

        /** The node within the pathname table that corresponds to this filer
         * window (and which is needed to deregister the pathname when this
         * window is destroyed). */

        pathname_table::node* _pathname_node;
        /** Construct filer window.
         * @param app the application to which this filer window belongs
         * @param pathname the pathname of the directory to be viewed
         * @param box the initial bounding box of the window
         * @param options the initial options for the filer window

        filer_window(filer_application* app,const char* pathname,
                const os_box& box,const filer_options& options);

        /** Destroy filer window. */

        virtual void handle_redraw_request(wimp_draw& block);
        virtual void handle_open_request(wimp_open& block);
        virtual void handle_close_request(wimp_close& block);
        virtual void handle_mouse_click(wimp_pointer& block);
        virtual void handle_user_drag_box(wimp_dragged& block);
        virtual void handle_key_pressed(wimp_key& block);
        virtual void handle_data_xfer(wimp_message& block);

        /** Handle menus deleted event.
         * The event should already have been handled by the menu itself.

        void handle_menus_deleted();

        /** Get pathname.
         * @return the pathname of the directory viewed by this filer window

        const char* pathname() const
                { return _pathname; }

        /** Get filer options.
         * @return the filer options applicable to this window

        const filer_options& options() const
                { return _options; }

        /** Set filer options.
         * @param options the required filer options

        void options(const filer_options& options);

        /** Get selection.
         * @return the content of this directory, with selected objected marked

        directory& selection()
                { return _directory; }

        /** Get temporary selection.
         * An object is temporarily selected if the user clicks menu above it
         * when no other objects are selected.  It is automatically deselected
         * when that menu is closed.
         * @return the index of the object temporarily selected,
         *  or directory::npos if none

        int temp_selection() const
                { return _temp_selection; }
        /** Get shared menu.
         * One copy of the menu is shared between all filer windows.
         * @return a reference to the shared menu

        filer_menu& shared_menu() const;

        /** Reload directory listing. */
        void reload();

        /** Reformat content of window. */
        void reformat();

        /** Reformat content of window to given width.
         * @param xsize the required width

        void reformat(int xsize);

        /** Set extent of work area.
         * If the extent of the visible area matches the extent of the work
         * area (in one or both directions) then the visible area is resized
         * automatically to match the work area (in the directions that match).
         * @param extent the required extent

        void set_extent(const os_box& extent);

        /** Find the cell which contains a given point.
         * @param p the point to be found
         * @return the cell index if found, otherwise npos

        unsigned int find_cell(const os_coord& p);

        /** Force a redraw of a given cell.
         * @param index the index of the cell to be redrawn

        void force_redraw_cell(unsigned int index);

        /** Open rename field.
         * @param index the index of the object to be renamed
         * @param pos the position of the pointer
         * @param buffer the buffer to be used to hold the leafname
         * @return the icon handle

        wimp_i open_rename(directory::size_type index,os_coord pos,char* buffer);

        /** Close rename field.
         * @param i the icon handle

        void close_rename(wimp_i i,directory::size_type index);

        /** Rename object.
         * @param index the index of the object to be renamed
         * @param leafname the new leafname for the object

        void rename(directory::size_type index,const char* leafname);
        /** Refresh window.
         * The directory is re-read from disc.  The current selection is
         * preserved so far as is possible.

        void refresh();

        /** Select or deselect all objects
         * @param selected the required selection state

        void select_all(int selected);

        /** Open filer window for parent directory.
         * @param offset the position at which to open the top left-hand
         *  corner of the new filer window, with respect to the top left-hand
         *  corner of this one

        void open_parent(const os_coord& offset) const;

        /** Set the current work directory to this directory. */
        void set_work_directory() const;

        /** Begin an operation on the current selection using the
         * FilerAction module.
         * This function performs the first three steps of the procedure
         * for starting an operation using this module:
         * - it executes the command Filer_Action;
         * - it calls FilerAction_SendSelectedDirectory;
         * - it calls FilerAction_SendSelectedFile for each member of the
         *   current selection.
         * The final step, sending a Message_FilerAction (either directly
         * or via FilerAction_SendStartOperation), must be done separately.
         * @return the task handle to which the Message_FilerAction must
         *  be sent

        wimp_t begin_filer_action();

        /** Run object
         * Note that setting the close parameter does not actually cause
         * the parent window to be closed, however the information is
         * needed because it affected the location at which a child
         * directory is opened.
         * @param info the directory entry for the object to be run
         * @param close true if the parent window is to be closed, otherwise false
         * @param shift true if shift was pressed, otherwise false

        void run(osgbpb_info& info,int close,int shift);