//
// [email protected] would like to here about your fixes!
// http://www.geocities.com/SiliconValley/Hills/1836/
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include "dir.h"
#include "bmps.h"
Display *disp;
Widget outer, canvas;
XtAppContext app_con;
XColor color[6];
Folder Froot;
void WinEvent(Widget , caddr_t, XEvent *);
main (int argc, char **argv)
{
int i;
long eventmask = ButtonPressMask|ExposureMask|KeyPressMask;
long fgcolor, bgcolor;
color[0].red = 65535;
color[0].green = 65535;
color[0].blue = 65535;
color[1].red = 0;
color[1].green = 0;
color[1].blue = 0;
color[2].red = 65535;
color[2].green = 65535;
color[2].blue = 0;
color[3].red = 49344;
color[3].green = 49344;
color[3].blue = 49344;
color[5].red = 49344;
color[5].green = 0;
color[5].blue = 0;
outer = XtAppInitialize(&app_con,"XDraw",NULL,0,&argc,argv,NULL,NULL,0);
disp = XtDisplay(outer);
canvas = XtVaCreateManagedWidget ("canvas",constraintWidgetClass,outer,
XtNallowVert, True,
XtNallowHoriz, True,
XtNwidth, 400,
XtNheight,600,
XtNuseBottom, True, NULL,0);
XtRealizeWidget(outer);
//
// Allocate colours
//
for(i=0;i<6;i++)
{
XAllocColor(disp,DefaultColormap(disp,DefaultScreen(disp)),&color[i]);
}
//
// set double click time 1/2 second
//
XtSetMultiClickTime(disp,500);
XtAddEventHandler(canvas,eventmask,FALSE,(XtEventHandler)WinEvent,NULL);
Froot.parent = NULL;
Froot.position.x = 0;
Froot.position.y = 0;
Froot.position.xc = 16;
Froot.position.yc = 16;
Froot.isExpanded = FALSE;
Froot.win = XtWindow(canvas);
Froot.tgc = XCreateGC(disp,Froot.win, 0,NULL);
// init using root
DIR *directory;
strcpy(Froot.fullpath,"/");
directory = opendir(Froot.fullpath);
Froot.dp = readdir(directory);
closedir(directory);
strcpy(Froot.dp->d_name ,"/");
Froot.Open();
Froot.Draw(0,0);
XtAppMainLoop(app_con);
}
void WinEvent(Widget w,caddr_t nil,XEvent *event)
{
Window win;
GC tgc;
int i,j;
XButtonEvent *e = (XButtonEvent *) event;
switch (event->type)
{
case KeyPress:
cout << "keypress" <y/16.),0);
XSetForeground(disp,Froot.tgc,color[0].pixel);
XFillRectangle(disp,Froot.win,Froot.tgc,0,0,(unsigned int)800,(unsigned int)800);
Froot.Draw(0,0);
break;
case Expose:
XSetForeground(disp,Froot.tgc,color[0].pixel);
XFillRectangle(disp,Froot.win,Froot.tgc,0,0,(unsigned int)800,(unsigned int)800);
Froot.Draw(0,0);
break;
default:
break;
}
win = XtWindow(w);
tgc = XCreateGC(disp,win, 0,NULL);
}
Folder::Folder()
{
nSiblings = 0;
isExpanded = FALSE;
}
int Folder::Draw(int depth,int stack)
{
int i,j,k,newstack;
position.x = depth*16;
position.y = stack*16;
stack++;
if(S_ISDIR(fstat.st_mode) && isExpanded == FALSE)
DrawIcon(dir_closed);
else if(S_ISREG(fstat.st_mode))
DrawIcon(file_unknown);
else if(S_ISLNK(fstat.st_mode))
DrawIcon(dir_link);
else if(S_ISSOCK(fstat.st_mode))
DrawIcon(dir_link);
else
DrawIcon(dir_open);
//
// print name
//
XSetBackground(disp,tgc,color[0].pixel);
XSetForeground(disp,tgc,color[1].pixel);
XDrawImageString(disp,win,tgc,position.x+16,position.y+12,fullpath,strlen(fullpath));
//
Selectable tmp;
int ilist =0;
for(k=0;k 0;i++)
{
tmp.position.x = (depth-1)*16;
tmp.position.y = i*16;
tmp.DrawIcon(tree_fill);
}
stack = newstack;
}
return stack;
}
int Folder::Expand(int stack_id,int cu_stack)
{
int i;
for(i=0;id_name);
if( stat(Siblings[nSiblings].fullpath,&Siblings[nSiblings].fstat) == 0) // file stats
{
if(S_ISREG(Siblings[nSiblings].fstat.st_mode)) // files will not expand
Siblings[nSiblings].isExpanded = TRUE;
if(!(strcmp(Siblings[nSiblings].dp->d_name,"..")==0))
if(!(strcmp(Siblings[nSiblings].dp->d_name,".")==0))
nSiblings++;
}
}
isExpanded = TRUE;
closedir(directory);
return 1;
}
int Folder::Close()
{
if(Siblings > 0)
free(Siblings);
nSiblings = 0;
isExpanded =FALSE;
return 0;
}
int Selectable::DrawIcon(int icon[16][16])
{
for(int i=0;i<16;i++)
{
for(int j=0;j<16;j++)
{
XSetForeground(disp,tgc,color[icon[i][j]].pixel);
XDrawPoint(disp,win,tgc,position.x+j,position.y+i);
}
}
return 0;
}