SEAL Forum Index SEAL
The SEAL Forums
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Wastebasket code

 
Post new topic   Reply to topic    SEAL Forum Index -> General
View previous topic :: View next topic  
Author Message
Darragh McNally



Joined: 03 Apr 2002
Posts: 196
Location: Ireland

PostPosted: Sun Sep 08, 2002 7:38 am    Post subject: Wastebasket code Reply with quote

Something for Seal2 people 2 look at(it doesnt work too well and deres more code than this):
Code:


/*
   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.
*/

/* SEAL WasteBasket
   Copyright(c) Darragh McNally 2002.
   All Rights Reserved Worldwide.
*/

#include"seal.h"
#include"menus.h"
#include"app.h"
#include"button.h"
#include"dialogs.h"
#include"iodlg.h"

#include <stdio.h>
#include <zlib.h>
#include <string.h>
#include <dos.h>
#include <dir.h>

l_text dc_standard_path1 = "waste/";
#define current_path "C:/"
#define MSG_COPYF    10003
#define MSG_RENAMEF  10004
#define MSG_DELETEF  10006
#define MSG_RESTOREF 10005

#define DC_SIZEX   620
#define DC_SIZEY   300
#ifndef TXT_CANTRUNFILE
#define TXT_CANTRUNFILE        INI_TEXT("Can't run file")
#endif

p_textline    text_line = NULL;
p_filelistbox box1 = NULL;
p_stattext statc = NULL;

static p_list get_infile_items ( void )
{
  p_list p = list_init(malloc(sizeof(t_list)), &free_filehistory_item, 0);

  if ( p )
  {
     p->insert(p, new_filehistory_item("All files (*.*)", "*.*"));
  };

  return p;
};

static void trans_ev ( p_object o, t_event *e )
{
  RETVIEW(o, e);

  if ( o->phase == PH_PREPROCESS && e->type & EV_KEYBOARD ) {


        if ( keyb->code == TO_KEY(KB_ENTER) &&
            OBJECT(text_line)->is_state(OBJECT(text_line), OB_SF_FOCUSED) ) {

           if ( !run_file(text_line->text) )

               seal_error(ERR_INFO, "%s\n\n%s", TXT_CANTRUNFILE, text_line->text);

            clear_event(e);

       };

       if ( keyb->code == TO_KEY(KB_F1) ) { // copy


            clear_event(e);

            e->type = EV_MESSAGE;
            e->message = MSG_COPYF;
       };

       if ( keyb->code == TO_KEY(KB_F2) ) { // rename


            clear_event(e);

            e->type = EV_MESSAGE;
            e->message = MSG_RENAMEF;
       };

                if ( keyb->code == TO_KEY(KB_F3) ) { // restore


            clear_event(e);

            e->type = EV_MESSAGE;
            e->message = MSG_RESTOREF;
           };

       if ( keyb->code == TO_KEY(KB_F4) ) { // delete


            clear_event(e);

            e->type = EV_MESSAGE;
            e->message = MSG_DELETEF;
       };


  };

if ( o->phase == PH_POSTPROCESS && e->type & EV_MESSAGE ) {

      switch ( e->message ) {


          case MSG_COPYF : {

               message(OBJECT(box1), EV_MESSAGE, MSG_COPY, OBJECT(box1));

               clear_event(e);

          }; break;

          case MSG_RENAMEF : {

               message(OBJECT(box1), EV_MESSAGE, MSG_CHANGENAME, OBJECT(box1));

               clear_event(e);

          }; break;

          case MSG_RESTOREF : {

    char srcbuf[2000];
    char destbuf[2000];
    uLongf destsize, srcsize;

    FILE  *src, *dest;

    l_text filename = FILELISTBOX_ITEM_FILENAME(LISTBOX(o)->list, LISTBOX(o)->current);
    l_text fileout = save_dialog(current_path, filename, get_infile_items());

   src = fopen(filename, "rb");
   fread(srcbuf, destsize, 1, src);
   fclose(src);

   srcsize = destsize;
   uncompress(destbuf, &destsize, srcbuf, srcsize);

   dest = fopen(fileout, "wb");
   fwrite(destbuf, destsize, 1, dest);
   fclose(dest);


    clear_event(e);

    message(OBJECT(box1), EV_MESSAGE, MSG_CUT, OBJECT(box1));

    clear_event(e);
         }; break;

          case MSG_DELETEF : {

              message(OBJECT(box1), EV_MESSAGE, MSG_CUT, OBJECT(box1));

               clear_event(e);

          }; break;


      };


  };


};


static t_point  dc_size_minimum ( p_view o )
{
   return point_assign(DC_SIZEX/2+100, 150);
};


void  init_dc ( void )
{

   t_rect r = rect_assign(0, 0, DC_SIZEX, DC_SIZEY);
   t_rect t = r;
   t_rect s = r;

   p_button b = NULL;

   p_filelistctrl  dir1;
   p_filelistctrl  dir2;

   p_appwin o = appwin_init(_malloc(sizeof(t_appwin)), /* make window */
                            r,
                            "Waste Basket",
                            WF_MINIMIZE|WF_MAXIMIZE,
                            ap_id, /* application id */
                            &trans_ev);

  o->icon16 = load_image("bmp/trash.ico,16");

   VIEW(o)->align |= TX_ALIGN_CENTER; /* set alignment */

   VIEW(o)->size_minimum = &dc_size_minimum;

   OBJECT(desktop)->insert(OBJECT(desktop), OBJECT(o)); /* insert it on the desktop */

   r = VIEW(o)->size_limits(VIEW(o));

   s = r = rect_assign(r.a.x+10, r.a.y+10, t.b.x-10, r.b.y-20);

   r = rect_assign(r.a.x, r.a.y, r.a.x+(DC_SIZEX)-20, r.b.y);

   t = r;

   r.a.y += 30;

   box1 = filelistbox_init(_malloc(sizeof(t_filelistbox)), r, 2, LF_SELECTABLE|FL_OPEN, dc_standard_path1, "*.*", FA_ALL, NULL);

   if ( box1 ) {


        /* redeclare alignment of filelistbox 1 */
        VIEW(box1)->align |= TX_ALIGN_BOTTOM|TX_ALIGN_RIGHT;
   };

   r = rect_assign(t.a.x, t.a.y, t.a.x+10, t.a.y+20);

   /* make link for box1 */
   dir1 = filelistctrl_init(_malloc(sizeof(t_filelistctrl)), r, box1);

   OBJECT(o)->insert(OBJECT(o), OBJECT(box1)); /* insert it on the desktop */


   s = rect_assign(s.a.x, s.b.y+30, s.b.x-5, s.b.y+50);


   r = rect_assign(r.b.x+10, r.a.y, r.b.x+75, r.b.y);

   statc = stattext_init(malloc(sizeof(t_stattext)),r, TX_ALIGN_LEFT, "Waste:");

   OBJECT(o)->insert(OBJECT(o), OBJECT(statc));


   r = rect_assign(r.b.x+10, r.a.y, r.b.x+75, r.b.y);

   b = button_init(_malloc(sizeof(t_button)), r, "Copy", MSG_COPYF, BF_NORMAL );

   VIEW(b)->align |= TX_ALIGN_BOTTOM|TX_ALIGN_FIXEDY;

   OBJECT(o)->insert(OBJECT(o), OBJECT(b));


   r = rect_assign(r.b.x+10, r.a.y, r.b.x+75, r.b.y);

   b = button_init(_malloc(sizeof(t_button)), r, "Rename", MSG_RENAMEF, BF_NORMAL );

   VIEW(b)->align |= TX_ALIGN_BOTTOM|TX_ALIGN_FIXEDY;

   OBJECT(o)->insert(OBJECT(o), OBJECT(b));


   r = rect_assign(r.b.x+10, r.a.y, r.b.x+75, r.b.y);

   b = button_init(_malloc(sizeof(t_button)), r, "Restore", MSG_RESTOREF, BF_NORMAL );

   VIEW(b)->align |= TX_ALIGN_BOTTOM|TX_ALIGN_FIXEDY;

   OBJECT(o)->insert(OBJECT(o), OBJECT(b));


   r = rect_assign(r.b.x+10, r.a.y, r.b.x+75, r.b.y);

   b = button_init(_malloc(sizeof(t_button)), r, "Delete", MSG_DELETEF, BF_NORMAL );

   VIEW(b)->align |= TX_ALIGN_BOTTOM|TX_ALIGN_FIXEDY;

   OBJECT(o)->insert(OBJECT(o), OBJECT(b));

};


app_begin ( void ) {


  if ( ap_process == AP_INIT ) {

      if ( ap_args ) dc_standard_path1 = ap_args;
      init_dc();

  };

  if ( ap_process == AP_FREE ) {

  };

} app_end;
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    SEAL Forum Index -> General All times are GMT - 7 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group