File:  [Public] / Amaya / amaya / templates.c
Revision 1.58: download - view: text, annotated - select for diffs
Fri Jun 23 14:40:28 2006 UTC (17 years, 11 months ago) by francesc
Branches: MAIN
CVS tags: HEAD
Now the template structure is private. It is a cleaner solution

/*
 *
 *  COPYRIGHT INRIA and W3C, 1996-2005
 *  Please first read the full copyright statement in file COPYRIGHT.
 *
 */
 
/*
 * Authors: Francesc Campoy Flores
 *
 */

#define THOT_EXPORT extern
#include "amaya.h"
#include "document.h"

#ifdef TEMPLATES
#include "Template.h"
#include "templateDeclarations.h"

struct menuType
{
	char *label;
	int   type;
};

#include "appdialogue_wx.h"
#include "init_f.h"
#include "wxdialogapi_f.h"
#include "templatesStructure_f.h"
#endif /* TEMPLATES */

/*----------------------------------------------------------------------
  NewTemplate: Create the "new document from template" dialog
  ----------------------------------------------------------------------*/
void NewTemplate (Document doc, View view)
{
#ifdef TEMPLATES
  char *templateDir = TtaGetEnvString ("TEMPLATES_DIRECTORY");
  ThotBool created;

  if (templates == NULL)
    InitializeTemplateEnvironment();
  created = CreateNewTemplateDocDlgWX(BaseDialog + OpenTemplate,
                                      TtaGetViewFrame (doc, view), doc,
                                      TtaGetMessage (AMAYA, AM_NEW_TEMPLATE),templateDir);
  
  if (created)
    {
      TtaSetDialoguePosition ();
      TtaShowDialogue (BaseDialog + OpenTemplate, TRUE);
    }

  if(templateDir) TtaFreeMemory(templateDir);
#endif /* TEMPLATES */
}

/*----------------------------------------------------------------------
  Load a template and create the instance file - update images and 
  stylesheets related to the template.
  ----------------------------------------------------------------------*/
int CreateInstanceOfTemplate (Document doc, char *templatename, char *docname,
                              DocumentType docType)
{
#ifdef TEMPLATES

	LoadTemplate(doc, templatename, docname, docType, TRUE);
#endif /* TEMPLATES */
	return 0;
}

#ifdef TEMPLATES
/*----------------------------------------------------------------------
  ----------------------------------------------------------------------*/
static void giveItems(char *text, int size, struct menuType **items, int *nbitems)
{
	ThotBool         inElement = TRUE;
  struct menuType *menu;
  char            *iter;
	char             temp[128];
  int              i;
	int              labelSize;

	*nbitems = 1;
	for (i = 0; i < size; i++)
    {
      if (isEOSorWhiteSpace (text[i]))
        {
          if (inElement)
            inElement = FALSE;
        }
      else if (!inElement)
        {
          inElement = TRUE;
          (*nbitems)++;
        }
    }

	menu = (struct menuType*) TtaGetMemory(sizeof(struct menuType)* *nbitems);
	iter = text;
	for (i = 0; i < *nbitems; i++)
    {		
      labelSize = 0;
      while (isEOSorWhiteSpace (*iter))
        iter++;

      while (!isEOSorWhiteSpace (*iter))
        {
          temp[labelSize++] = *iter;
          iter++;
        }

      temp[labelSize] = EOS;
      menu[i].label = (char *) TtaStrdup(temp);
      menu[i].type = SIMPLE_TYPE;
      *items = menu;
    }
}

/*----------------------------------------------------------------------
  ----------------------------------------------------------------------*/
static char *createMenuString (const struct menuType* items, const int nbItems)
{
  char *result, *iter;
	int   size = 0;
  int   i;

	for (i=0; i < nbItems; i++)
		size += 2 + strlen (items[i].label);

	result = (char *) TtaGetMemory(size);
	iter = result;
	for (i=0; i < nbItems; i++)
    {
      *iter = 'B';
      ++iter;
		
      strcpy (iter, items[i].label);
      iter += strlen (items[i].label)+1;
    }
	return result;
}

#endif /* TEMPLATES */

/*----------------------------------------------------------------------
  ThotBool UseMenuClicked (Document doc) 
  Shows a menu with all the types that can be used in a use element.
  ----------------------------------------------------------------------*/
ThotBool UseMenuClicked (NotifyElement *event)
{
#ifdef TEMPLATES
	Document         doc = event->document;
	Element          el = TtaGetParent(event->element);
	ElementType      elt = TtaGetElementType(el);
	Attribute        at;
	AttributeType    att;
	int              nbitems, size;
	struct menuType *items;
  char            *types, *menuString;
	
	att.AttrSSchema = elt.ElSSchema;
	att.AttrTypeNum = Template_ATTR_types;
	at = TtaGetAttribute (el, att);

	size = TtaGetTextAttributeLength (at);
	types = (char *) TtaGetMemory (size+1);	
	TtaGiveTextAttributeValue (at, types, &size);

	giveItems (types, size, &items, &nbitems);
	menuString = createMenuString (items, nbitems);

	TtaNewScrollPopup (BaseDialog + OptionMenu, TtaGetViewFrame (doc, 1), NULL, 
                     nbitems, menuString , NULL, false, 'L');

	TtaFreeMemory (menuString);
	TtaFreeMemory (types);

	TtaShowDialogue (BaseDialog + OptionMenu, FALSE);
	TtaWaitShowProcDialogue();
	TtaDestroyDialogue (BaseDialog + OptionMenu);

#endif /* TEMPLATES */
	//ReturnOption
	return TRUE;
}

/*----------------------------------------------------------------------
  ThotBool BagMenuClicked (Document doc) 
  Shows a menu with all the types that can be used in a use element.
  ----------------------------------------------------------------------*/
ThotBool BagMenuClicked (NotifyElement *event)
{
#ifdef TEMPLATES
#endif /* TEMPLATES */
	return TRUE;
}


Webmaster