Subversion Repositories Filer-Free

Rev

Rev 34 | Rev 36 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 34 Rev 35
Line 2... Line 2...
2
// Copyright © 2007 Graham Shaw.
2
// Copyright © 2007 Graham Shaw.
3
// Redistribution and modification are permitted under the terms of the
3
// Redistribution and modification are permitted under the terms of the
4
// GNU General Public License (version 2 or any later version).
4
// GNU General Public License (version 2 or any later version).
5
 
5
 
6
#include <cstring>
6
#include <cstring>
-
 
7
#include <cstdio>
-
 
8
 
-
 
9
#include "oslib/osbyte.h"
-
 
10
#include "oslib/wimp.h"
7
 
11
 
8
#include "template_loader.h"
12
#include "template_loader.h"
9
#include "layout_method.h"
13
#include "layout_method.h"
10
#include "filer_menu.h"
14
#include "filer_menu.h"
11
#include "filer_window.h"
15
#include "filer_window.h"
12
#include "filer_application.h"
16
#include "filer_application.h"
13
 
17
 
-
 
18
namespace {
-
 
19
 
-
 
20
/** The maximum length of a leafname. */
-
 
21
const size_t max_name_length=256;
-
 
22
 
-
 
23
/** The initial horizontal offset for opening a subdirectory. */
-
 
24
const int open_xstart=20;
-
 
25
 
-
 
26
/** The initial vertical offset for opening a subdirectory. */
-
 
27
const int open_ystart=-32;
-
 
28
 
-
 
29
/** The horizontal offset between subdirectories. */
-
 
30
const int open_xstep=20;
-
 
31
 
-
 
32
/** The vertical offset between subdirectories. */
-
 
33
const int open_ystep=0;
-
 
34
 
-
 
35
/** The number of distinct subdirectory offsets. */
-
 
36
const unsigned int open_count=8;
-
 
37
 
-
 
38
}; /* anonymous namespace */
-
 
39
 
14
filer_window::filer_window(filer_application* app,const char* pathname,
40
filer_window::filer_window(filer_application* app,const char* pathname,
15
        const os_box& box,const filer_options& options):
41
        const os_box& box,const filer_options& options):
16
        window(app),
42
        window(app),
17
        _pathname(new char[std::strlen(pathname)+1]),
43
        _pathname(new char[std::strlen(pathname)+1]),
18
        _options(options),
44
        _options(options),
19
        _directory(options.sort()),
45
        _directory(options.sort()),
20
        _xcsize(68),
46
        _xcsize(68),
21
        _ycsize(68),
47
        _ycsize(68),
22
        _xccount(1),
48
        _xccount(1),
23
        _yccount(1),
49
        _yccount(1),
24
        _temp_selection(directory::npos)
50
        _temp_selection(directory::npos),
-
 
51
        _auto_pos(open_xstart,open_ystart,open_xstep,open_ystep,open_count)
25
{
52
{
26
        // Copy pathname into buffer owned by this object.
53
        // Copy pathname into buffer owned by this object.
27
        std::strcpy(_pathname,pathname);
54
        std::strcpy(_pathname,pathname);
28
 
55
 
29
        // Load directory listing.
56
        // Load directory listing.
Line 167... Line 194...
167
void filer_window::handle_mouse_click(wimp_pointer& block)
194
void filer_window::handle_mouse_click(wimp_pointer& block)
168
{
195
{
169
        // Fetch layout.
196
        // Fetch layout.
170
        layout_method& layout=options().layout();
197
        layout_method& layout=options().layout();
171
 
198
 
-
 
199
        // Read shift state.
-
 
200
        int shift_state=0;
-
 
201
        xosbyte1(osbyte_VAR_KEYBOARD_STATE,0,0xff,&shift_state);
-
 
202
        int shift=(shift_state&0x08)!=0;
-
 
203
 
172
        // Find cell under pointer.
204
        // Find cell under pointer.
173
        unsigned int index=find_cell(block.pos);
205
        unsigned int index=find_cell(block.pos);
174
 
206
 
-
 
207
        bool close=false;
175
        if (block.buttons==wimp_CLICK_MENU)
208
        if (block.buttons==wimp_CLICK_MENU)
176
        {
209
        {
177
                // Any existing menu will be deleted by this action.
210
                // Any existing menu will be deleted by this action.
178
                handle_menus_deleted();
211
                handle_menus_deleted();
179
 
212
 
Line 195... Line 228...
195
 
228
 
196
                // Update then open the menu.
229
                // Update then open the menu.
197
                shared_menu().update(this);
230
                shared_menu().update(this);
198
                shared_menu().show(block);
231
                shared_menu().show(block);
199
        }
232
        }
-
 
233
        else if (block.buttons&(wimp_DOUBLE_ADJUST|wimp_DOUBLE_SELECT))
-
 
234
        {
-
 
235
                // If double click within a cell then run that object.
-
 
236
                if (index!=directory::npos)
-
 
237
                {
-
 
238
                        select_all(0);
-
 
239
                        close=(block.buttons&wimp_DOUBLE_ADJUST)!=0;
-
 
240
                        if (close) close_window();
-
 
241
                        run(*_directory[index],close,shift);
-
 
242
                }
-
 
243
        }
200
        else if (block.buttons&(wimp_SINGLE_SELECT|wimp_SINGLE_ADJUST))
244
        else if (block.buttons&(wimp_SINGLE_SELECT|wimp_SINGLE_ADJUST))
201
        {
245
        {
202
                // If single select click then first de-select everything.
246
                // If single select click then first de-select everything.
203
                if (block.buttons&wimp_SINGLE_SELECT) select_all(0);
247
                if (block.buttons&wimp_SINGLE_SELECT) select_all(0);
204
 
248
 
Line 207... Line 251...
207
                {
251
                {
208
                        _directory[index].selected(!_directory[index].selected());
252
                        _directory[index].selected(!_directory[index].selected());
209
                        force_redraw_cell(index);
253
                        force_redraw_cell(index);
210
                }
254
                }
211
        }
255
        }
-
 
256
 
-
 
257
        // If this window has closed as a result of the mouse event
-
 
258
        // then delete it.
-
 
259
        if (close) delete this;
212
}
260
}
213
 
261
 
214
void filer_window::handle_menus_deleted()
262
void filer_window::handle_menus_deleted()
215
{
263
{
216
        if (_temp_selection!=directory::npos)
264
        if (_temp_selection!=directory::npos)
Line 407... Line 455...
407
                new filer_window((filer_application*)parent_application(),
455
                new filer_window((filer_application*)parent_application(),
408
                        _pathname,box,_options);
456
                        _pathname,box,_options);
409
                *lastdot='.';
457
                *lastdot='.';
410
        }
458
        }
411
}
459
}
-
 
460
 
-
 
461
void filer_window::run(osgbpb_info& info,int close,int shift)
-
 
462
{
-
 
463
        // Need to at least partially handle shift key here, because
-
 
464
        // Filer_Run does not allow coordinates to be specified when
-
 
465
        // shift-clicking an application directory.
-
 
466
        // (... unless there is an alternative way to invoke Filer_Run?)
-
 
467
 
-
 
468
        static char buffer[12+max_name_length];
-
 
469
        if ((info.obj_type&fileswitch_IS_DIR)&&((info.name[0]!='!')||shift))
-
 
470
        {
-
 
471
                // Get dimensions of this window.
-
 
472
                wimp_window_state state;
-
 
473
                get_window_state(state);
-
 
474
 
-
 
475
                // Choose coordinates for new window.
-
 
476
                // If closing this window then open in same position,
-
 
477
                // otherwise open below and to the right.
-
 
478
                os_coord offset=_auto_pos();
-
 
479
                os_box box;
-
 
480
                box.x0=state.visible.x0+((close)?0:offset.x);
-
 
481
                box.y1=state.visible.y1+((close)?0:offset.y);
-
 
482
                box.x1=box.x0;
-
 
483
                box.y0=box.y1;
-
 
484
 
-
 
485
                // Open new window.
-
 
486
                if (std::strlen(_pathname)+std::strlen(info.name)+1<max_name_length)
-
 
487
                {
-
 
488
                        std::sprintf(buffer,"%s.%s",_pathname,info.name);
-
 
489
                        window* w=new filer_window(
-
 
490
                                (filer_application*)parent_application(),
-
 
491
                                buffer,box,_options);
-
 
492
                }
-
 
493
        }
-
 
494
        else
-
 
495
        {
-
 
496
                // Run object.
-
 
497
                if (std::strlen(_pathname)+std::strlen(info.name)+1<max_name_length)
-
 
498
                {
-
 
499
                        std::sprintf(buffer,"Run %s.%s",_pathname,info.name);
-
 
500
                        wimp_start_task(buffer);
-
 
501
                }
-
 
502
        }
-
 
503
}