- Main Page
- Related Pages
- Data Structures
- Files
- Examples

- File List

# /home/v/Kate/WORK_TREES/kate-sorceress-backup/v/src/kate/src/kate_event.c

    00001 /* Copyright (C) 2008 Vincent Penquerc'h.
    00002    This file is part of the Kate codec library.
    00003    Written by Vincent Penquerc'h.
    00004
    00005    Use, distribution and reproduction of this library is governed
    00006    by a BSD style source license included with this source in the
    00007    file 'COPYING'. Please read these terms before distributing. */
    00008
    00009
    00010 #define KATE_INTERNAL
    00011 #include "kate_internal.h"
    00012
    00013 #ifdef HAVE_STDLIB_H
    00014 #include <stdlib.h>
    00015 #endif
    00016 #include "kate/kate.h"
    00017
    00018 static int kate_event_init(kate_event *ev,const kate_info *ki)
    00019 {
    00020   if (!ev || !ki) return KATE_E_INVALID_PARAMETER;
    00021
    00022   ev->start_time=-1;
    00023   ev->duration=-1;
    00024   ev->backlink=-1;
    00025   ev->id=-1;
    00026
    00027   ev->text_encoding=ki->text_encoding;
    00028   ev->text_directionality=ki->text_directionality;
    00029   ev->text_markup_type=ki->text_markup_type;
    00030   ev->language=NULL;
    00031   ev->text=NULL;
    00032   ev->len=0;
    00033
    00034   ev->nmotions=0;
    00035   ev->motions=NULL;
    00036
    00037   ev->region=NULL;
    00038   ev->style=NULL;
    00039   ev->secondary_style=NULL;
    00040   ev->font_mapping=NULL;
    00041   ev->palette=NULL;
    00042   ev->bitmap=NULL;
    00043
    00044   ev->nbitmaps=0;
    00045   ev->bitmaps=NULL;
    00046
    00047   /* internal */
    00048   ev->ki=ki;
    00049   ev->trackers=0;
    00050
    00051   return 0;
    00052 }
    00053
    00054 kate_event *kate_event_create(const kate_info *ki)
    00055 {
    00056   kate_event *ev;
    00057
    00058   if (!ki) return NULL;
    00059
    00060   ev=(kate_event*)kate_malloc(sizeof(kate_event));
    00061   if (!ev) return NULL;
    00062   if (kate_event_init(ev,ki)<0) {
    00063     kate_free(ev);
    00064     return NULL;
    00065   }
    00066
    00067   return ev;
    00068 }
    00069
    00070 int kate_event_destroy(kate_event *ev)
    00071 {
    00072   size_t n;
    00073
    00074   if (!ev) return KATE_E_INVALID_PARAMETER;
    00075   if (!ev->ki) return KATE_E_INIT;
    00076   if (ev->trackers) return KATE_E_INIT;
    00077
    00078   if (ev->language) kate_free(ev->language);
    00079   kate_free(ev->text);
    00080   if (ev->motions) {
    00081     kate_motion_destroy(ev->ki,ev->motions,NULL,ev->nmotions,0);
    00082   }
    00083
    00084   if (ev->region && kate_find_region(ev->ki,ev->region)<0) {
    00085     kate_free(ev->region);
    00086   }
    00087   if (ev->style && kate_find_style(ev->ki,ev->style)<0) {
    00088     if (ev->style->font) kate_free(ev->style->font);
    00089     kate_free(ev->style);
    00090   }
    00091   if (ev->secondary_style && kate_find_style(ev->ki,ev->secondary_style)<0) {
    00092     kate_free(ev->secondary_style);
    00093   }
    00094   if (ev->font_mapping && kate_find_font_mapping(ev->ki,ev->font_mapping)<0) {
    00095     kate_free(ev->font_mapping);
    00096   }
    00097   if (ev->palette && kate_find_palette(ev->ki,ev->palette)<0) {
    00098     kate_free(ev->palette->colors);
    00099     kate_free(ev->palette);
    00100   }
    00101
    00102   if (ev->bitmaps) {
    00103     for (n=0;n<ev->nbitmaps;++n) {
    00104       if (ev->bitmaps[n] && kate_find_bitmap(ev->ki,ev->bitmaps[n])<0) {
    00105         kate_free(ev->bitmaps[n]->pixels);
    00106         kate_free(ev->bitmaps[n]);
    00107       }
    00108     }
    00109     kate_free(ev->bitmaps);
    00110   }
    00111   if (ev->bitmap && kate_find_bitmap(ev->ki,ev->bitmap)<0) {
    00112     kate_free(ev->bitmap->pixels);
    00113     kate_free(ev->bitmap);
    00114   }
    00115
    00116   kate_free(ev);
    00117
    00118   return 0;
    00119 }
    00120
    00121 int kate_event_track(kate_event *ev)
    00122 {
    00123   if (!ev) return KATE_E_INVALID_PARAMETER;
    00124
    00125   ++ev->trackers;
    00126
    00127   return 0;
    00128 }
    00129
    00130 int kate_event_release(kate_event *ev)
    00131 {
    00132   if (!ev) return KATE_E_INVALID_PARAMETER;
    00133   if (ev->trackers==0) return KATE_E_INIT;
    00134
    00135   if (--ev->trackers==0) kate_event_destroy(ev);
    00136
    00137   return 0;
    00138 }
    00139