Subversion Repositories Filer-Free

Rev

Rev 16 | 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 <cstring>
#include <new>

#include "menu_item.h"
#include "menu.h"
#include "application.h"

menu::menu(application* app,char* title,unsigned int size):
        component(app),
        _data(0)
{
        // Allocate data block.
        _data=(wimp_menu*)new(std::nothrow)
                char[sizeof(wimp_menu)+size*sizeof(wimp_menu_entry)];

        // Initialise menu header.
        std::strcpy(_data->title_data.text,title);
        _data->title_fg=wimp_COLOUR_BLACK;
        _data->title_bg=wimp_COLOUR_LIGHT_GREY;
        _data->work_fg=wimp_COLOUR_BLACK;
        _data->work_bg=wimp_COLOUR_WHITE;
        _data->width=64;
        _data->height=44;
        _data->gap=0;

        // Initialise menu items.
        for (unsigned int i=0;i!=size;++i)
        {
                _data->entries[i].menu_flags=0;
                _data->entries[i].sub_menu=0;
                _data->entries[i].icon_flags=
                        wimp_ICON_TEXT|
                        wimp_ICON_INDIRECTED|
                        (wimp_BUTTON_MENU_ICON << wimp_ICON_BUTTON_TYPE_SHIFT)|
                        (wimp_COLOUR_BLACK << wimp_ICON_FG_COLOUR_SHIFT)|
                        (wimp_COLOUR_WHITE << wimp_ICON_BG_COLOUR_SHIFT);
                _data->entries[i].data.indirected_text.text="";
                _data->entries[i].data.indirected_text.validation=0;
                _data->entries[i].data.indirected_text.size=8;
        }
        if (size) _data->entries[size-1].menu_flags|=wimp_MENU_LAST;
}

menu::~menu()
{
        // Deallocate data block.
        delete[] (char*)_data;
}

void menu::handle_menu_selection(wimp_selection& block)
{}

void menu::handle_menus_deleted()
{}

void menu::show(wimp_pointer& block)
{
        // Register menu with application.
        application* app=parent_application();
        if (app) app->register_menu(*this);

        // Open menu, 64 OS units to the left of the pointer.
        xwimp_create_menu(_data,block.pos.x-64,block.pos.y);
}