4,13 → 4,39 |
// GNU General Public License (version 2 or any later version). |
|
#include <cstring> |
#include <cstdio> |
|
#include "oslib/osbyte.h" |
#include "oslib/wimp.h" |
|
#include "template_loader.h" |
#include "layout_method.h" |
#include "filer_menu.h" |
#include "filer_window.h" |
#include "filer_application.h" |
|
namespace { |
|
/** The maximum length of a leafname. */ |
const size_t max_name_length=256; |
|
/** The initial horizontal offset for opening a subdirectory. */ |
const int open_xstart=20; |
|
/** The initial vertical offset for opening a subdirectory. */ |
const int open_ystart=-32; |
|
/** The horizontal offset between subdirectories. */ |
const int open_xstep=20; |
|
/** The vertical offset between subdirectories. */ |
const int open_ystep=0; |
|
/** The number of distinct subdirectory offsets. */ |
const unsigned int open_count=8; |
|
}; /* anonymous namespace */ |
|
filer_window::filer_window(filer_application* app,const char* pathname, |
const os_box& box,const filer_options& options): |
window(app), |
21,7 → 47,8 |
_ycsize(68), |
_xccount(1), |
_yccount(1), |
_temp_selection(directory::npos) |
_temp_selection(directory::npos), |
_auto_pos(open_xstart,open_ystart,open_xstep,open_ystep,open_count) |
{ |
// Copy pathname into buffer owned by this object. |
std::strcpy(_pathname,pathname); |
169,9 → 196,15 |
// Fetch layout. |
layout_method& layout=options().layout(); |
|
// Read shift state. |
int shift_state=0; |
xosbyte1(osbyte_VAR_KEYBOARD_STATE,0,0xff,&shift_state); |
int shift=(shift_state&0x08)!=0; |
|
// Find cell under pointer. |
unsigned int index=find_cell(block.pos); |
|
bool close=false; |
if (block.buttons==wimp_CLICK_MENU) |
{ |
// Any existing menu will be deleted by this action. |
197,6 → 230,17 |
shared_menu().update(this); |
shared_menu().show(block); |
} |
else if (block.buttons&(wimp_DOUBLE_ADJUST|wimp_DOUBLE_SELECT)) |
{ |
// If double click within a cell then run that object. |
if (index!=directory::npos) |
{ |
select_all(0); |
close=(block.buttons&wimp_DOUBLE_ADJUST)!=0; |
if (close) close_window(); |
run(*_directory[index],close,shift); |
} |
} |
else if (block.buttons&(wimp_SINGLE_SELECT|wimp_SINGLE_ADJUST)) |
{ |
// If single select click then first de-select everything. |
209,6 → 253,10 |
force_redraw_cell(index); |
} |
} |
|
// If this window has closed as a result of the mouse event |
// then delete it. |
if (close) delete this; |
} |
|
void filer_window::handle_menus_deleted() |
409,3 → 457,47 |
*lastdot='.'; |
} |
} |
|
void filer_window::run(osgbpb_info& info,int close,int shift) |
{ |
// Need to at least partially handle shift key here, because |
// Filer_Run does not allow coordinates to be specified when |
// shift-clicking an application directory. |
// (... unless there is an alternative way to invoke Filer_Run?) |
|
static char buffer[12+max_name_length]; |
if ((info.obj_type&fileswitch_IS_DIR)&&((info.name[0]!='!')||shift)) |
{ |
// Get dimensions of this window. |
wimp_window_state state; |
get_window_state(state); |
|
// Choose coordinates for new window. |
// If closing this window then open in same position, |
// otherwise open below and to the right. |
os_coord offset=_auto_pos(); |
os_box box; |
box.x0=state.visible.x0+((close)?0:offset.x); |
box.y1=state.visible.y1+((close)?0:offset.y); |
box.x1=box.x0; |
box.y0=box.y1; |
|
// Open new window. |
if (std::strlen(_pathname)+std::strlen(info.name)+1<max_name_length) |
{ |
std::sprintf(buffer,"%s.%s",_pathname,info.name); |
window* w=new filer_window( |
(filer_application*)parent_application(), |
buffer,box,_options); |
} |
} |
else |
{ |
// Run object. |
if (std::strlen(_pathname)+std::strlen(info.name)+1<max_name_length) |
{ |
std::sprintf(buffer,"Run %s.%s",_pathname,info.name); |
wimp_start_task(buffer); |
} |
} |
} |