Subversion Repositories Filer-Free


Rev 59 | 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 "oslib/wimp.h"

#include "window_table.h"

class window;
class menu;

/** A class to represent a RISC OS application. */
class application
        /** The application name.
         * This is a copy of the pointer passed into the constructor.
         * The data itself is the original, not a copy.

        const char* _appname;

        /** The task handle. */
        wimp_t _handle;

        /** The quit flag.
         * True to terminate the application at the end of the current iteration
         * of the poll loop, otherwise false.

        bool _quit;

        /** A table of windows indexed by handle. */
        window_table _windows;

        /** The current menu, or 0 if none. */
        menu* _current_menu;

        /** The window that owns the current drag operation, or 0 if none. */
        window* _current_drag;
        /** Construct application.
         * The character string containing the application name must remain
         * in existance for the lifetime of the application object.
         * (This saves memory in the most common use case.)
         * @param appname the name of the application
         * @param messages a list of message numbers which the application
         *  should receive

        application(const char* appname,wimp_message_list* messages);

        /** Destroy application. */
        virtual ~application();

        /** Run application
         * @param pollword a pointer to an optional pollword

        void run(int* pollword=0);

        /** Get task handle.
         * @return the task handle of the application

        wimp_t handle()
                { return _handle; }

        /** Find window associated with given handle.
         * @param handle the window handle to be found
         * @return the associated window, or 0 if not found

        window* find_window(wimp_w handle);

        /** Get wimp poll flags.
         * By default all flags are zero (no events masked).
         * @return the required wimp poll flags

        virtual wimp_poll_flags poll_flags();

        /** Handle an event from the window manager.
         * @param event the window manager event number
         * @param the window manager event block
         * @param pollword a pointer to the pollword, or 0 if none

        virtual void handle_event(wimp_event_no event,wimp_block& block,
                int* pollword);

        /** Handle mouse click.
         * @param block the mouse click event block

        virtual void handle_mouse_click(wimp_pointer& block);

        /** Handle key press.
         * @param block the key press notification

        virtual void handle_key_pressed(wimp_key& block);

        /** Handle pollword non-zero.
         * @param pollword a pointer to the pollword, or 0 if none

        virtual void handle_pollword_non_zero(int* pollword);

        /** Handle user message.
         * @param event the window manager event number
         * @param the window manager event block

        virtual void handle_user_message(wimp_event_no event,
                wimp_message& message);

        /** Register window.
         * A window object should be registered when the underlying
         * RISC OS window is created and remain registered until that
         * window is destroyed.
         * @param w the window to be registered

        virtual void register_window(window& w);

        /** Deregister window.
         * @param w the window to be deregistered

        virtual void deregister_window(window& w);

        /** Register menu.
         * The menu will be automatically de-registered when it is closed.
         * @param m the menu to be registered

        void register_menu(menu& m);

        /** Register drag.
         * The drag will be automatically de-registered when it is closed.
         * The specified window becomes the owner of the current drag operation,
         * and will therefore receive any events associated with the drag.

        void register_drag(window& w);