1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165
|
/* Copyright (C) 1994 - 1996
Olav Woelfelschneider (wosch@rbg.informatik.th-darmstadt.de)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "../config.h"
#include <stdio.h>
#include <errno.h>
#include <sys/time.h>
#include <strings.h>
#include <stdlib.h>
#include <X11/Xlib.h>
#include <McTools/McApp.h>
#include <McTools/McGadget.h>
#include <McTools/McFocus.h>
#include <McTools/McSlider.h>
#include <McTools/McText.h>
#include <McTools/McBitmap.h>
#include <McTools/McString.h>
#include <McTools/McSelector.h>
#include <McTools/McResource.h>
#include <McTools/McUtils.h>
#include <McTools/McChoice.h>
#include <McTools/McInfoRequest.h>
#include "xmdb.h"
#include "newdir.h"
/*****************************************************************************
*
* Private definitons
*
*/
#define WIDTH 320
#define HEIGHT 100
typedef struct newdir_t {
unsigned char *root;
McGadget *strgad;
} newdir_t;
/*****************************************************************************
*
* Private variables and procedures
*
*/
static int event_proc(McWindow *mcw, XEvent *event);
static void cancel_proc(McGadget *gadget);
static void create_proc(McGadget *gadget);
/*****************************************************************************
*
* Pop up the newdir window
*
*/
void create_newdir_window(McApp *app,
unsigned char *root, unsigned char *path) {
McGadget *gad, *strgad;
McWindow *mcw;
newdir_t *newdir;
newdir = malloc(sizeof(newdir_t));
newdir->root=root;
/*
* Create the window
*/
mcw=McCreateSimpleWindow(app, _("New Cathegory"),
WIDTH, HEIGHT, WIDTH, HEIGHT,
WIDTH>>1, HEIGHT-20,
NULL, event_proc);
MakeText(mcw, 0, 10, 0, _("Please enter name of new cathegory"));
strgad=MakeString(mcw, 20, 35, WIDTH-40, 17, 0, path, NULL, create_proc);
newdir->strgad=strgad;
strgad->customData=newdir;
McAddFocusGadget(strgad, 1);
gad=MakeButton(mcw, 12, -8, 60, 16, 0, _("Create"), create_proc);
gad->topLeftGravity = SouthWestGravity;
gad->customData=newdir;
McAddFocusGadget(gad, 1);
mcw->mainButton=gad;
gad=MakeButton(mcw, -12, -8, 60, 16, 0, _("Cancel"), cancel_proc);
gad->topLeftGravity = SouthEastGravity;
gad->customData=newdir;
McAddFocusGadget(gad, 1);
/*
* Display the window
*/
McInitGadgets(mcw);
McMapWindow(mcw);
McSetFocus(strgad);
return;
}
/**************************************************************************/
static int event_proc(McWindow *mcw, XEvent *event) {
switch(event->type) {
case ClientMessage:
if ((event->xclient.format == 32) &&
(event->xclient.data.l[0] == mcw->app->wmDelWin)) {
if (mcw) {
newdir_t *newdir = (newdir_t *)mcw->customData;
McFreeWindow(mcw);
free(newdir);
}
return 1;
}
}
return 0;
}
/**************************************************************************/
static void cancel_proc(McGadget *gadget) {
newdir_t *newdir = (newdir_t *)gadget->customData;
free(newdir);
McFreeWindow(gadget->mcw);
}
/**************************************************************************/
static void create_proc(McGadget *gadget) {
newdir_t *newdir = (newdir_t *)gadget->customData;
unsigned char *buf, *in;
int len;
in = ((McString *)(newdir->strgad->specialInfo))->buf;
while((*in==32) || (*in==9)) in++;
len=strlen(in);
while((len>0) && ((in[len-1]==32) || (in[len-1]==9))) len--;
in[len]=0;
if (len) {
buf = alloca(strlen(newdir->root)+strlen(in)+10);
strcpy(buf, newdir->root);
if (buf[(len=strlen(buf))-1]!='/') { buf[len++]='/'; buf[len]=0; }
strcat(buf, in);
new_cathegory(buf);
McFreeWindow(gadget->mcw);
free(newdir);
}
}
|