Subversion Repositories Filer-Free

Rev

Rev 16 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
16 gdshaw@RISCPKG.ORG 1
// This file is part of the free Filer module for RISC OS.
2
// Copyright  2007 Graham Shaw.
3
// Redistribution and modification are permitted under the terms of the
4
// GNU General Public License (version 2 or any later version).
5
 
6
#include <cstring>
64 gdshaw@RISCPKG.ORG 7
#include <new>
16 gdshaw@RISCPKG.ORG 8
 
9
#include "menu_item.h"
10
#include "menu.h"
11
#include "application.h"
12
 
13
menu::menu(application* app,char* title,unsigned int size):
14
        component(app),
15
        _data(0)
16
{
17
        // Allocate data block.
64 gdshaw@RISCPKG.ORG 18
        _data=(wimp_menu*)new(std::nothrow)
19
                char[sizeof(wimp_menu)+size*sizeof(wimp_menu_entry)];
16 gdshaw@RISCPKG.ORG 20
 
21
        // Initialise menu header.
22
        std::strcpy(_data->title_data.text,title);
23
        _data->title_fg=wimp_COLOUR_BLACK;
24
        _data->title_bg=wimp_COLOUR_LIGHT_GREY;
25
        _data->work_fg=wimp_COLOUR_BLACK;
26
        _data->work_bg=wimp_COLOUR_WHITE;
27
        _data->width=64;
28
        _data->height=44;
29
        _data->gap=0;
30
 
31
        // Initialise menu items.
32
        for (unsigned int i=0;i!=size;++i)
33
        {
34
                _data->entries[i].menu_flags=0;
35
                _data->entries[i].sub_menu=0;
36
                _data->entries[i].icon_flags=
37
                        wimp_ICON_TEXT|
38
                        wimp_ICON_INDIRECTED|
39
                        (wimp_BUTTON_MENU_ICON << wimp_ICON_BUTTON_TYPE_SHIFT)|
40
                        (wimp_COLOUR_BLACK << wimp_ICON_FG_COLOUR_SHIFT)|
41
                        (wimp_COLOUR_WHITE << wimp_ICON_BG_COLOUR_SHIFT);
42
                _data->entries[i].data.indirected_text.text="";
43
                _data->entries[i].data.indirected_text.validation=0;
44
                _data->entries[i].data.indirected_text.size=8;
45
        }
46
        if (size) _data->entries[size-1].menu_flags|=wimp_MENU_LAST;
47
}
48
 
49
menu::~menu()
50
{
51
        // Deallocate data block.
52
        delete[] (char*)_data;
53
}
54
 
55
void menu::handle_menu_selection(wimp_selection& block)
56
{}
57
 
58
void menu::handle_menus_deleted()
59
{}
60
 
61
void menu::show(wimp_pointer& block)
62
{
63
        // Register menu with application.
64
        application* app=parent_application();
65
        if (app) app->register_menu(*this);
66
 
67
        // Open menu, 64 OS units to the left of the pointer.
68
        xwimp_create_menu(_data,block.pos.x-64,block.pos.y);
69
}