Subversion Repositories Filer-Free

Rev

Rev 25 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
21 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>
7
 
8
#include "template_loader.h"
9
#include "sort_by_name.h"
10
#include "filer_window.h"
11
#include "filer_application.h"
12
 
13
namespace {
14
 
15
sort_by_name _sort_by_name;
16
 
17
}; /* anonymous namespace */
18
 
19
filer_window::filer_window(filer_application* app,const char* pathname,
20
        const os_box& box):
21
        window(app),
22
        _pathname(new char[std::strlen(pathname)+1]),
23
        _directory(_sort_by_name)
24
{
25
        // Copy pathname into buffer owned by this object.
26
        std::strcpy(_pathname,pathname);
27
 
28
        // Load directory listing.
29
        reload();
30
 
31
        // Create window from template.
32
        template_loader loader("directory","Resources:$.Resources.Filer.Templates");
33
        wimp_window& wblock=loader;
34
        wblock.title_flags|=wimp_ICON_INDIRECTED;
35
        wblock.title_data.indirected_text.text=_pathname;
36
        wblock.title_data.indirected_text.validation="";
37
        wblock.title_data.indirected_text.size=strlen(_pathname);
38
        wblock.visible=box;
39
        wblock.extent.x0=0;
40
        wblock.extent.y0=-(box.y1-box.y0);
41
        wblock.extent.x1=box.x1-box.x0;
42
        wblock.extent.y1=0;
43
        wblock.icon_count=0;
44
        create_window(wblock);
45
 
46
        // Resize extent to match actual visible area.
47
        wimp_window_state wstate;
48
        get_window_state(wstate);
49
        os_box extent;
50
        extent.x0=0;
51
        extent.y0=-(wstate.visible.y1-wstate.visible.y0);
52
        extent.x1=wstate.visible.x1-wstate.visible.x0;
53
        extent.y1=0;
54
        window::set_extent(extent);
55
 
56
        // Open window.
57
        wimp_window_info winfo;
58
        get_window_info_header(winfo);
59
        wimp_open open;
60
        open.visible.x0=winfo.visible.x0;
61
        open.visible.y0=winfo.visible.y1-(winfo.extent.y1-winfo.extent.y0);
62
        open.visible.x1=winfo.visible.x0+(winfo.extent.x1-winfo.extent.x0);
63
        open.visible.y1=winfo.visible.y1;
64
        open.visible=winfo.visible;
65
        open.xscroll=0;
66
        open.yscroll=0;
67
        open.next=wimp_TOP;
68
        open_window(open);
69
}
70
 
71
filer_window::~filer_window()
72
{
73
        // Delete pathname buffer.
74
        delete[] _pathname;
75
}
76
 
77
void filer_window::handle_redraw_request(wimp_draw& block)
78
{
79
        int more=0;
80
        xwimp_redraw_window(&block,&more);
81
        while (more)
82
        {
83
                xwimp_get_rectangle(&block,&more);
84
        }
85
}
86
 
87
void filer_window::reload()
88
{
89
        static int buffer[256];
90
        _directory.load(_pathname,buffer,sizeof(buffer));
91
}