Subversion Repositories Filer-Free


Rev 31 | Rev 33 | Go to most recent revision | 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 "window.h"
#include "filer_options.h"

class filer_menu;
class filer_application;

/** A class to represent a filer window. */
class filer_window:
        public window
        /** 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;
        /** 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);

        /** 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);

        /** 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);
        /** 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;