home *** CD-ROM | disk | FTP | other *** search
/ The Best of Mecomp Multimedia 2 / MECOMP-CD-II.iso / amiga / programmieren / gui / ieditor / loaders / gtb / funcs.c next >
Encoding:
C/C++ Source or Header  |  1997-06-17  |  24.0 KB  |  865 lines

  1. /*
  2.     GTB.loader
  3.     Copyright ©1996 Simone Tellini
  4.          All Rights Reserved
  5.  
  6.     Take this as an example... ;-)
  7. */
  8.  
  9. /// Include
  10. #define INTUI_V36_NAMES_ONLY
  11. #define CATCOMP_NUMBERS
  12.  
  13. #include <exec/types.h>                 // exec
  14. #include <exec/lists.h>
  15. #include <exec/memory.h>
  16. #include <exec/nodes.h>
  17. #include <exec/execbase.h>
  18. #include <dos/dos.h>                    // dos
  19. #include <intuition/intuition.h>        // intuition
  20. #include <intuition/gadgetclass.h>
  21. #include <libraries/gadtools.h>         // libraries
  22. #include <gadtoolsbox/forms.h>          // gadtoolsbox
  23. #include <gadtoolsbox/gui.h>
  24. #include <clib/exec_protos.h>           // protos
  25. #include <clib/dos_protos.h>
  26. #include <clib/gtx_protos.h>
  27. #include <clib/nofrag_protos.h>
  28. #include <clib/utility_protos.h>
  29. #include <pragmas/exec_pragmas.h>
  30. #include <pragmas/dos_pragmas.h>
  31. #include <pragmas/gtx_pragmas.h>
  32. #include <pragmas/nofrag_pragmas.h>
  33. #include <pragmas/graphics_pragmas.h>
  34. #include <pragmas/utility_pragmas.h>
  35.  
  36. #include <stdarg.h>
  37. #include <string.h>
  38. #include <stdio.h>
  39. #include <stdlib.h>
  40. #include <ctype.h>
  41.  
  42. #include "DEV_IE:Loaders/defs.h"
  43. ///
  44. /// Prototypes
  45. static BOOL                 ConvertMenus( struct IE_Data *, struct WindowInfo *, struct ExtMenuList * );
  46. static BOOL                 ConvertIText( struct IE_Data *, struct WindowInfo *, struct IntuiText * );
  47. static BOOL                 ConvertBox( struct IE_Data *, struct WindowInfo *, struct BevelBox * );
  48. static struct WindowInfo   *ConvertWin( struct IE_Data *, struct ProjectWindow * );
  49. static BOOL                 ConvertGad( struct IE_Data *, struct WindowInfo *, struct ExtNewGadget * );
  50. static ULONG                ConvertScr( struct IE_Data *, GUIDATA * );
  51. static ULONG                ConvertColors( struct IE_Data *, UWORD, GUIDATA * );
  52.  
  53. extern struct GTXBase *GTXBase;
  54. extern struct Library *GfxBase;
  55. ///
  56. /// Data
  57. static const UBYTE  Bar_txt[] = "---------------------------";
  58.  
  59. static const UWORD stringjusts[] = {
  60.     GACT_STRINGLEFT, GACT_STRINGRIGHT, GACT_STRINGCENTER
  61. };
  62.  
  63. static const ULONG gadget_flags[] = { 1, 2, 4, 8, 16, 0 };
  64. ///
  65.  
  66.  
  67. // Conversion routines
  68. /// Windows
  69. struct WindowInfo *ConvertWin( struct IE_Data *IE, struct ProjectWindow *from )
  70. {
  71.     struct WindowInfo   *wnd;
  72.     struct Screen       *scr;
  73.  
  74.     if( wnd = ( *IE->Functions->AllocObject )( IE_WINDOW )) {
  75.  
  76.     NewList( &wnd->wi_Gadgets );
  77.     NewList( &wnd->wi_Menus   );
  78.     NewList( &wnd->wi_Boxes   );
  79.     NewList( &wnd->wi_Images  );
  80.     NewList( &wnd->wi_ITexts  );
  81.  
  82.     AddTail( (struct List *)&IE->win_list, (struct Node *)wnd );
  83.  
  84.     IE->num_win += 1;
  85.  
  86.     wnd->wi_name = wnd->wi_Titolo;
  87.  
  88.     wnd->wi_Flags           = from->pw_WindowFlags;
  89.     wnd->wi_IDCMP           = from->pw_IDCMP;
  90.     wnd->wi_InnerWidth      = from->pw_InnerWidth;
  91.     wnd->wi_InnerHeight     = from->pw_InnerHeight;
  92.     wnd->wi_MouseQueue      = from->pw_MouseQueue;
  93.     wnd->wi_RptQueue        = from->pw_RptQueue;
  94.  
  95.     if( from->pw_TagFlags & WDF_INNERWIDTH )
  96.         wnd->wi_flags1 |= W_USA_INNER_W;
  97.  
  98.     if( from->pw_TagFlags & WDF_INNERHEIGHT )
  99.         wnd->wi_flags1 |= W_USA_INNER_H;
  100.  
  101.     if( from->pw_TagFlags & WDF_MOUSEQUEUE )
  102.         wnd->wi_Tags |= W_MOUSEQUEUE;
  103.  
  104.     if( from->pw_TagFlags & WDF_RPTQUEUE )
  105.         wnd->wi_Tags |= W_RPTQUEUE;
  106.  
  107.     if( from->pw_TagFlags & WDF_AUTOADJUST )
  108.         wnd->wi_Tags |= W_AUTOADJUST;
  109.  
  110.     if( from->pw_TagFlags & WDF_FALLBACK )
  111.         wnd->wi_Tags |= W_FALLBACK;
  112.  
  113.     if( from->pw_TagFlags & WDF_ZOOM ) {
  114.         wnd->wi_Tags   |= W_ZOOM;
  115.         wnd->wi_ZLeft   = wnd->wi_ZTop = -1;    // don't move
  116.         wnd->wi_ZWidth  = wnd->wi_Width;
  117.         wnd->wi_ZHeight = IE->ScreenData->YOffset + 1;
  118.     }
  119.  
  120.     scr = IE->ScreenData->Screen;
  121.  
  122.     wnd->wi_Left     = GetTagData( WA_Left, 0, from->pw_Tags );
  123.     wnd->wi_Top      = GetTagData( WA_Top,  0, from->pw_Tags );
  124.  
  125.     wnd->wi_Width    = wnd->wi_InnerWidth + scr->WBorRight + scr->WBorLeft;
  126.     wnd->wi_Height   = wnd->wi_InnerHeight + IE->ScreenData->YOffset + 1 + scr->WBorBottom;
  127.     wnd->wi_MaxWidth = wnd->wi_MaxHeight = -1;
  128.  
  129.     strcpy( wnd->wi_Titolo,         from->pw_WindowTitle );
  130.     strcpy( wnd->wi_TitoloSchermo,  from->pw_ScreenTitle );
  131.     strcpy( wnd->wi_Label,          from->pw_Name        );
  132.  
  133.     #ifdef DEBUG
  134.     Printf( "WINDOW: %s\n", wnd->wi_Titolo );
  135.     #endif
  136.  
  137.     struct ExtNewGadget *gad;
  138.     for( gad = from->pw_Gadgets.gl_First; gad->en_Next; gad = gad->en_Next )
  139.         if(!( ConvertGad( IE, wnd, gad )))
  140.         return( NULL );
  141.     #ifdef DEBUG
  142.     Printf( "ConvertGad() OK\n" );
  143.     #endif
  144.  
  145.     struct BevelBox     *box;
  146.     for( box = from->pw_Boxes.bl_First; box->bb_Next; box = box->bb_Next )
  147.         if(!( ConvertBox( IE, wnd, box )))
  148.         return( NULL );
  149.     #ifdef DEBUG
  150.     Printf( "ConvertBox() OK\n" );
  151.     #endif
  152.  
  153.     struct IntuiText    *txt;
  154.     txt = from->pw_WindowText;
  155.     while( txt ) {
  156.         if(!( ConvertIText( IE, wnd, txt )))
  157.         return( NULL );
  158.         txt = txt->NextText;
  159.     }
  160.     #ifdef DEBUG
  161.     Printf( "ConvertIText() OK\n" );
  162.     #endif
  163.  
  164.     if(!( ConvertMenus( IE, wnd, &from->pw_Menus )))
  165.         return( NULL );
  166.     #ifdef DEBUG
  167.     Printf( "ConvertMenus() OK\n" );
  168.     #endif
  169.  
  170.     }
  171.  
  172.     return( wnd );
  173. }
  174. ///
  175. /// IntuiTexts
  176. BOOL ConvertIText( struct IE_Data *IE, struct WindowInfo *wnd, struct IntuiText *from )
  177. {
  178.     struct ITextNode   *itn, *itn2;
  179. /*    struct TxtAttrNode *fnt; */
  180.  
  181.     if( itn = ( *IE->Functions->AllocObject )( IE_INTUITEXT )) {
  182.  
  183.     AddTail(( struct List * )&wnd->wi_ITexts, ( struct Node * )itn );
  184.     itn->itn_Node.ln_Name = itn->itn_IText = itn->itn_Text;
  185.  
  186.     wnd->wi_NumTexts += 1;
  187.  
  188.     itn2 = itn->itn_Node.ln_Pred;
  189.  
  190.     if( itn2->itn_Node.ln_Pred )
  191.         itn2->itn_NextText = &itn->itn_FrontPen;
  192.  
  193.     strcpy( itn->itn_Text, from->IText );
  194.  
  195.     itn->itn_FrontPen = from->FrontPen;
  196.     itn->itn_BackPen  = from->BackPen;
  197.     itn->itn_DrawMode = from->DrawMode;
  198.     itn->itn_LeftEdge = from->LeftEdge;
  199.     itn->itn_TopEdge  = from->TopEdge;
  200.  
  201.     itn->itn_Node.ln_Type |= IT_SCRFONT;
  202.  
  203. /*
  204.     This part causes some Enforcer hits, probably because GTB puts
  205.     some strange data in the ITextFont field of IntuiText...
  206.     Anyway, if you manage to fix this... ;-)
  207.  
  208.     if( from->ITextFont ) {
  209.         if( fnt = ( *IE->Functions->AddFont )( from->ITextFont )) {
  210.  
  211.         if(!( fnt->txa_Ptr ))
  212.             IE->flags |= NODISKFONT;
  213.         else
  214.             itn->itn_Node.ln_Type &= ~IT_SCRFONT;
  215.  
  216.         itn->itn_FontCopy = &fnt->txa_FontName;
  217.         } else
  218.         IE->flags |= NODISKFONT;
  219.  
  220.         if(!( itn->itn_Node.ln_Type & IT_SCRFONT ))
  221.         itn->itn_ITextFont = itn->itn_FontCopy;
  222.     }  */
  223.  
  224.     } else
  225.     return( FALSE );
  226.  
  227.     return( TRUE );
  228. }
  229. ///
  230. /// Bevel Box
  231. BOOL ConvertBox( struct IE_Data *IE, struct WindowInfo *wnd, struct BevelBox *from )
  232. {
  233.     struct BevelBoxNode    *box;
  234.  
  235.     if( box = ( *IE->Functions->AllocObject )( IE_BEVELBOX )) {
  236.  
  237.     AddTail( (struct List *)&wnd->wi_Boxes, (struct Node *)box );
  238.  
  239.     wnd->wi_NumBoxes += 1;
  240.  
  241.     box->bb_VITag       = GT_VisualInfo;
  242.     box->bb_TTag        = GTBB_FrameType;
  243.     box->bb_RTag        = TAG_IGNORE;
  244.  
  245.     box->bb_Left        = from->bb_Left;
  246.     box->bb_Top         = from->bb_Top;
  247.     box->bb_Width       = from->bb_Width;
  248.     box->bb_Height      = from->bb_Height;
  249.  
  250.     if( from->bb_Flags & BBF_RECESSED ) {
  251.         box->bb_RTag = GTBB_Recessed;
  252.         box->bb_Recessed = TRUE;
  253.     }
  254.  
  255.     box->bb_FrameType = ( from->bb_Flags & BBF_DROPBOX ) ? BBFT_ICONDROPBOX : BBFT_BUTTON;
  256.  
  257.     } else {
  258.     return( FALSE );
  259.     }
  260.  
  261.     return( TRUE );
  262. }
  263. ///
  264. /// Gadgets
  265. BOOL ConvertGad( struct IE_Data *IE, struct WindowInfo *wnd, struct ExtNewGadget *from )
  266. {
  267.     struct GadgetInfo      *gad;
  268.     struct GadgetScelta    *gs;
  269.     UBYTE                 **labels;
  270.     UWORD                   cnt, cnt2;
  271.     UBYTE                  *ptr, ch;
  272.  
  273.     if(( from->en_Kind >= BOOLEAN ) || ( from->en_Kind == GENERIC_KIND ))
  274.     return( TRUE );
  275.  
  276.     if(!( gad = ( *IE->Functions->AllocObject )( IE_GADGET )))
  277.     return( FALSE );
  278.  
  279.     AddTail( (struct List *)&wnd->wi_Gadgets, (struct Node *)gad );
  280.  
  281.     gad->g_UserData     = gad;
  282.     gad->g_VisualInfo   = IE->ScreenData->Visual;
  283.     gad->g_GadgetText   = gad->g_Titolo;
  284.  
  285.     NewList( &gad->g_Scelte );
  286.  
  287.     gad->g_Kind = from->en_Kind;
  288.  
  289.     // NewGadget structure
  290.     gad->g_Left     = from->en_NewGadget.ng_LeftEdge;
  291.     gad->g_Top      = from->en_NewGadget.ng_TopEdge - IE->ScreenData->YOffset;
  292.     gad->g_Width    = from->en_NewGadget.ng_Width;
  293.     gad->g_Height   = from->en_NewGadget.ng_Height;
  294.     gad->g_Flags    = from->en_NewGadget.ng_Flags;
  295.  
  296.     // strings
  297.     strcpy( gad->g_Titolo, from->en_GadgetText );
  298.     strcpy( gad->g_Label, from->en_GadgetLabel );
  299.  
  300.     #ifdef DEBUG
  301.     Printf( "    - Gadget: %s  \t  Kind: %ld\n", gad->g_Titolo, gad->g_Kind );
  302.     #endif
  303.  
  304.     // let's alloc some space for its string
  305.     if(( gad->g_Kind == STRING_KIND ) || ( gad->g_Kind == TEXT_KIND )) {
  306.     if(!( gad->g_ExtraMem = AllocVec( 120, MEMF_CLEAR ))) {
  307.         Remove(( struct Node *)gad );
  308.         ( *IE->Functions->FreeObject )( gad, IE_GADGET );
  309.         return( FALSE );
  310.     }
  311.     }
  312.  
  313.     // Now we translate the tags. Note my more compact way of storing
  314.     // them *;D
  315.  
  316.     switch( from->en_Kind ) {
  317.  
  318.     case CHECKBOX_KIND:
  319.         if( GTX_TagInArray( GTCB_Checked, from->en_Tags ))
  320.         gad->g_Tags |= 2;
  321.         if( GTX_TagInArray( GA_Disabled, from->en_Tags ))
  322.         gad->g_Tags |= 2;
  323.         break;
  324.  
  325.     case CYCLE_KIND:
  326.  
  327.         labels = (UBYTE **)GetTagData( GTCY_Labels, NULL, from->en_Tags );
  328.  
  329.         // count the labels
  330.         cnt = 0;
  331.         while( labels[ cnt ] )
  332.         cnt++;
  333.  
  334.         gad->g_NumScelte = cnt;
  335.  
  336.         for( cnt2 = 0; cnt2 < gad->g_NumScelte; cnt2++ ) {
  337.         if(!( gs = ( *IE->Functions->AllocObject )( IE_ITEM )))
  338.             return( FALSE );
  339.  
  340.         AddTail( (struct List *)&gad->g_Scelte, (struct Node *)gs );
  341.         gs->gs_Node.ln_Name = gs->gs_Testo;
  342.  
  343.         strcpy( gs->gs_Testo, *labels++ );
  344.         }
  345.  
  346.         if( GTX_TagInArray( GTCY_Active, from->en_Tags ))
  347.         ((struct CK)( gad->g_Data )).Act = GetTagData( GTCY_Active, NULL, from->en_Tags );
  348.         if( GTX_TagInArray( GA_Disabled, from->en_Tags ))
  349.         gad->g_Tags |= 2;
  350.         break;
  351.  
  352.     case    INTEGER_KIND:
  353.         if ( GTX_TagInArray( GA_TabCycle, from->en_Tags ))
  354.         gad->g_Tags |= 8;
  355.         if ( GTX_TagInArray( STRINGA_ExitHelp, from->en_Tags ))
  356.         gad->g_Tags |= 0x10;
  357.  
  358.         ((struct IK)( gad->g_Data )).Num = GetTagData( GTIN_Number, 0, from->en_Tags );
  359.  
  360.         ((struct IK)( gad->g_Data )).MaxC = GetTagData( GTIN_MaxChars, 10, from->en_Tags );
  361.  
  362.         if ( cnt = GetTagData( STRINGA_Justification, 0l, from->en_Tags )) {
  363.         cnt2 = 0;
  364.         while( stringjusts[ cnt2 ] != cnt )
  365.             cnt2++;
  366.         ((struct IK)( gad->g_Data )).Just = cnt2;
  367.         }
  368.         if( GTX_TagInArray( GA_Disabled, from->en_Tags ))
  369.         gad->g_Tags |= 2;
  370.         break;
  371.  
  372.     case    LISTVIEW_KIND:
  373.         if (GTX_TagInArray( GTLV_ShowSelected, from->en_Tags ))
  374.         gad->g_Tags |= 8;
  375.         if ( GTX_TagInArray( GTLV_ScrollWidth, from->en_Tags ))
  376.         ((struct LK)( gad->g_Data)).ScW = GetTagData( GTLV_ScrollWidth, 0, from->en_Tags );
  377.         else
  378.         ((struct LK)(gad->g_Data)).ScW = 16;
  379.         if ( GTX_TagInArray( GTLV_ReadOnly, from->en_Tags ))
  380.         gad->g_Tags |= 4;
  381.         if ( GTX_TagInArray( LAYOUTA_Spacing, from->en_Tags ))
  382.         ((struct LK)( gad->g_Data)).Spc = GetTagData( LAYOUTA_Spacing, 0, from->en_Tags );
  383.         if( GTX_TagInArray( GA_Disabled, from->en_Tags ))
  384.         gad->g_Tags |= 2;
  385.  
  386.         if( GTX_TagInArray( GTLV_Labels, from->en_Tags )) {
  387.         labels = (UBYTE **)GetTagData( GTLV_Labels, NULL, from->en_Tags );
  388.  
  389.         // count the labels
  390.         cnt = 0;
  391.         while( labels[ cnt ] )
  392.             cnt++;
  393.  
  394.         gad->g_NumScelte = cnt;
  395.  
  396.         for( cnt2 = 0; cnt2 < gad->g_NumScelte; cnt2++ ) {
  397.             if(!( gs = ( *IE->Functions->AllocObject )( IE_ITEM )))
  398.             return( FALSE );
  399.  
  400.             AddTail( (struct List *)&gad->g_Scelte, (struct Node *)gs );
  401.             gs->gs_Node.ln_Name = gs->gs_Testo;
  402.  
  403.             strcpy( gs->gs_Testo, *labels++ );
  404.         }
  405.         }
  406.         break;
  407.  
  408.     case    MX_KIND:
  409.         labels = (UBYTE **)GetTagData( GTMX_Labels, NULL, from->en_Tags );
  410.  
  411.         // count the labels
  412.         cnt = 0;
  413.         while( labels[ cnt ] )
  414.         cnt++;
  415.  
  416.         gad->g_NumScelte = cnt;
  417.  
  418.         for( cnt2 = 0; cnt2 < gad->g_NumScelte; cnt2++ ) {
  419.         if(!( gs = ( *IE->Functions->AllocObject )( IE_ITEM )))
  420.             return( FALSE );
  421.  
  422.         AddTail( (struct List *)&gad->g_Scelte, (struct Node *)gs );
  423.         gs->gs_Node.ln_Name = gs->gs_Testo;
  424.  
  425.         strcpy( gs->gs_Testo, *labels++ );
  426.         }
  427.  
  428.         if ( GTX_TagInArray( GTMX_Spacing, from->en_Tags ))
  429.         ((struct MK)( gad->g_Data )).Spc = GetTagData( GTMX_Spacing, 0, from->en_Tags );
  430.         else
  431.         ((struct MK)(gad->g_Data)).Spc = 1;
  432.         if ( GTX_TagInArray( GTMX_Active, from->en_Tags ))
  433.         ((struct MK)( gad->g_Data )).Act = GetTagData( GTMX_Active, 0, from->en_Tags );
  434.         if( GTX_TagInArray( GA_Disabled, from->en_Tags ))
  435.         gad->g_Tags |= 2;
  436.         break;
  437.  
  438.     case    PALETTE_KIND:
  439.         ((struct PK)( gad->g_Data)).Depth = GetTagData( GTPA_Depth, 1, from->en_Tags );
  440.         if ( GTX_TagInArray( GTPA_IndicatorWidth, from->en_Tags ))
  441.         ((struct PK)( gad->g_Data )).IW = GetTagData( GTPA_IndicatorWidth, NULL, from->en_Tags );
  442.         if ( GTX_TagInArray( GTPA_IndicatorHeight, from->en_Tags ))
  443.         ((struct PK)( gad->g_Data )).IH = GetTagData( GTPA_IndicatorHeight, NULL, from->en_Tags );
  444.         if ( GTX_TagInArray( GTPA_Color, from->en_Tags ))
  445.         ((struct PK)( gad->g_Data )).Color = GetTagData( GTPA_Color, 1, from->en_Tags );
  446.         else
  447.         ((struct PK)( gad->g_Data )).Color = 1;
  448.         if ( GTX_TagInArray( GTPA_ColorOffset, from->en_Tags ))
  449.         ((struct PK)( gad->g_Data)).ColOff = GetTagData( GTPA_ColorOffset, 0, from->en_Tags );
  450.         if( GTX_TagInArray( GA_Disabled, from->en_Tags ))
  451.         gad->g_Tags |= 2;
  452.         break;
  453.  
  454.     case    SCROLLER_KIND:
  455.         if ( GTX_TagInArray( GTSC_Top, from->en_Tags ))
  456.         ((struct SK)( gad->g_Data)).Top = GetTagData( GTSC_Top, NULL, from->en_Tags );
  457.         if ( GTX_TagInArray( GTSC_Total, from->en_Tags ))
  458.         ((struct SK)( gad->g_Data)).Tot = GetTagData( GTSC_Total, NULL, from->en_Tags );
  459.         if ( GTX_TagInArray( GTSC_Visible, from->en_Tags ))
  460.         ((struct SK)( gad->g_Data)).Vis = GetTagData( GTSC_Visible, NULL, from->en_Tags );
  461.         else
  462.         ((struct SK)(gad->g_Data)).Vis = 2;
  463.         if ( GTX_TagInArray( GTSC_Arrows, from->en_Tags ))
  464.         ((struct SK)( gad->g_Data)).Arr = GetTagData( GTSC_Arrows, 0, from->en_Tags );
  465.         if ( GTX_TagInArray( PGA_Freedom, from->en_Tags ))
  466.         ((struct SK)( gad->g_Data)).Free = 1;
  467.         if ( GTX_TagInArray( GA_Immediate, from->en_Tags ))
  468.         gad->g_Tags |= 8;
  469.         if ( GTX_TagInArray( GA_RelVerify, from->en_Tags ))
  470.         gad->g_Tags |= 4;
  471.         if( GTX_TagInArray( GA_Disabled, from->en_Tags ))
  472.         gad->g_Tags |= 2;
  473.         break;
  474.  
  475.     case    SLIDER_KIND:
  476.         if ( GTX_TagInArray( GTSL_Min, from->en_Tags ))
  477.         ((struct SlK)( gad->g_Data)).Min = GetTagData( GTSL_Min, NULL, from->en_Tags );
  478.         if ( GTX_TagInArray( GTSL_Max, from->en_Tags ))
  479.         ((struct SlK)( gad->g_Data)).Max = GetTagData( GTSL_Max, NULL, from->en_Tags );
  480.         else
  481.         ((struct SlK)( gad->g_Data)).Max = 15;
  482.         if ( GTX_TagInArray( GTSL_Level, from->en_Tags ))
  483.         ((struct SlK)( gad->g_Data)).Level = GetTagData( GTSL_Level, NULL, from->en_Tags );
  484.         if ( GTX_TagInArray( GTSL_MaxLevelLen, from->en_Tags ))
  485.         ((struct SlK)( gad->g_Data)).MLL = GetTagData( GTSL_MaxLevelLen, NULL, from->en_Tags );
  486.         else
  487.         ((struct SlK)( gad->g_Data)).MLL = 2;
  488.  
  489.         if ( GTX_TagInArray( GTSL_LevelFormat, from->en_Tags ))
  490.         strcpy( ((struct SlK)( gad->g_Data)).Format, ( UBYTE * )GetTagData( GTSL_LevelFormat, 0, from->en_Tags ));
  491.         else
  492.         strcpy( ((struct SlK)( gad->g_Data)).Format, "%ld" );
  493.  
  494.         if ( GTX_TagInArray( GTSL_LevelPlace, from->en_Tags )) {
  495.         cnt = GetTagData( GTSL_LevelPlace, NULL, from->en_Tags );
  496.  
  497.         cnt2 = 0;
  498.         while( gadget_flags[ cnt2 ] != cnt )
  499.             cnt2++;
  500.  
  501.         ((struct SlK)( gad->g_Data)).LevPlc = cnt2;
  502.         }
  503.         if ( GTX_TagInArray( PGA_Freedom, from->en_Tags ))
  504.         ((struct SlK)( gad->g_Data)).Free = 1;
  505.  
  506.         if ( GTX_TagInArray( GA_Immediate, from->en_Tags ))
  507.         gad->g_Tags |= 8;
  508.         if ( GTX_TagInArray( GA_RelVerify, from->en_Tags ))
  509.         gad->g_Tags |= 4;
  510.         if( GTX_TagInArray( GA_Disabled, from->en_Tags ))
  511.         gad->g_Tags |= 2;
  512.         break;
  513.  
  514.     case    STRING_KIND:
  515.         if ( GTX_TagInArray( GA_TabCycle, from->en_Tags ))
  516.         gad->g_Tags |= 8;
  517.         if ( GTX_TagInArray( STRINGA_ExitHelp, from->en_Tags ))
  518.         gad->g_Tags |= 0x10;
  519.         if ( ptr = ( UBYTE * )GetTagData( GTST_String, NULL, from->en_Tags )) {
  520.         strcpy( gad->g_ExtraMem, ptr );
  521.         }
  522.         ((struct StK)( gad->g_Data)).MaxC = GetTagData( GTST_MaxChars, 64, from->en_Tags );
  523.  
  524.         if ( cnt = GetTagData( STRINGA_Justification, 0l, from->en_Tags )) {
  525.         cnt2 = 0;
  526.         while( stringjusts[ cnt2 ] != cnt )
  527.             cnt2++;
  528.         ((struct StK)( gad->g_Data )).Just = cnt2;
  529.         }
  530.         if( GTX_TagInArray( GA_Disabled, from->en_Tags ))
  531.         gad->g_Tags |= 2;
  532.         break;
  533.  
  534.     case    NUMBER_KIND:
  535.         if ( GTX_TagInArray( GTNM_Number, from->en_Tags ))
  536.         ((struct NK)( gad->g_Data )).Num = GetTagData( GTNM_Number, 0, from->en_Tags );
  537.         if ( GTX_TagInArray( GTNM_Border, from->en_Tags ))
  538.         gad->g_Tags |= 2;
  539.         ((struct NK)(gad->g_Data)).MNL = 10;
  540.         ((struct NK)(gad->g_Data)).FPen = -1;
  541.         ((struct NK)(gad->g_Data)).BPen = -1;
  542.         strcpy( ((struct NK)(gad->g_Data)).Format, "%ld" );
  543.         break;
  544.  
  545.     case    TEXT_KIND:
  546.         {
  547.         STRPTR  txt;
  548.  
  549.         if( txt = (STRPTR)GetTagData( GTTX_Text, NULL, from->en_Tags ))
  550.             strcpy( gad->g_ExtraMem, txt );
  551.         }
  552.  
  553.         ((struct TK)(gad->g_Data)).FPen = -1;
  554.         ((struct TK)(gad->g_Data)).BPen = -1;
  555.  
  556.         if ( GTX_TagInArray( GTTX_Border, from->en_Tags ))
  557.         gad->g_Tags |= 4;
  558.         if ( GTX_TagInArray( GTTX_CopyText, from->en_Tags ))
  559.         gad->g_Tags |= 2;
  560.         break;
  561.  
  562.     }
  563.  
  564.     if( GTX_TagInArray( GT_Underscore, from->en_Tags ))
  565.     gad->g_Tags |= 1;
  566.  
  567.     // let's get the activation key
  568.     if( gad->g_Tags & 1 ) {
  569.     ptr = gad->g_Titolo;
  570.     do{
  571.         ch = *ptr++;
  572.     } while(( ch != '_' ) && ( ch != '\0' ));
  573.     if( ch ) {
  574.         gad->g_Key = *ptr;
  575.         wnd->wi_NumKeys += 1;
  576.     }
  577.     }
  578.  
  579.     wnd->wi_GadTypes[ gad->g_Kind - 1 ] += 1;
  580.     wnd->wi_NumGads += 1;
  581.  
  582.     return( TRUE );
  583. }
  584. ///
  585. /// Menus
  586. BOOL ConvertMenus( struct IE_Data *IE, struct WindowInfo *wnd, struct ExtMenuList *from )
  587. {
  588.     struct MenuTitle   *title;
  589.     struct _MenuItem   *item;
  590.     struct MenuSub     *sub;
  591.     struct ExtNewMenu  *from_m, *from_i, *from_s;
  592.  
  593.     for( from_m = from->ml_First; from_m->em_Next; from_m = from_m->em_Next ) {
  594.     if( title = ( *IE->Functions->AllocObject )( IE_MENUTITLE )) {
  595.  
  596.         AddTail( (struct List *)&wnd->wi_Menus, (struct Node *)title );
  597.         title->mt_Node.ln_Name = title->mt_Text;
  598.  
  599.         wnd->wi_NumMenus += 1;
  600.  
  601.         NewList( &title->mt_Items );
  602.  
  603.         strcpy( title->mt_Text, from_m->em_MenuTitle );
  604.         strcpy( title->mt_Label, from_m->em_MenuLabel );
  605.  
  606.         for( from_i = from_m->em_Items->ml_First; from_i->em_Next; from_i = from_i->em_Next ) {
  607.  
  608.         if( item = ( *IE->Functions->AllocObject )( IE_MENUITEM )) {
  609.  
  610.             AddTail( (struct List *)&title->mt_Items, (struct Node *)item );
  611.             item->min_Node.ln_Name = item->min_Text;
  612.             NewList( &item->min_Subs );
  613.  
  614.             title->mt_NumItems += 1;
  615.  
  616.             if( from_i->em_NewMenu.nm_Label == NM_BARLABEL ) {
  617.             item->min_Node.ln_Name = Bar_txt;
  618.             item->min_Flags       |= M_BARLABEL;
  619.             }
  620.  
  621.             strcpy( item->min_Text, from_i->em_MenuTitle );
  622.             strcpy( item->min_CommKey, from_i->em_CommKey );
  623.             strcpy( item->min_Label, from_i->em_MenuLabel );
  624.  
  625.             item->min_MutualExclude = from_i->em_NewMenu.nm_MutualExclude;
  626.  
  627.             for( from_s = from_i->em_Items->ml_First; from_s->em_Next; from_s = from_s->em_Next ) {
  628.  
  629.             if( sub = ( *IE->Functions->AllocObject )( IE_MENUSUB )) {
  630.  
  631.                 AddTail( (struct List *)&item->min_Subs, (struct Node *)sub );
  632.                 sub->msn_Node.ln_Name = sub->msn_Text;
  633.  
  634.                 item->min_NumSubs += 1;
  635.  
  636.                 if( from_s->em_NewMenu.nm_Label == NM_BARLABEL ) {
  637.                 sub->msn_Node.ln_Name = Bar_txt;
  638.                 sub->msn_Flags       |= M_BARLABEL;
  639.                 }
  640.  
  641.                 strcpy( sub->msn_Text, from_s->em_MenuTitle );
  642.                 strcpy( sub->msn_CommKey, from_s->em_CommKey );
  643.                 strcpy( sub->msn_Label, from_s->em_MenuLabel );
  644.  
  645.                 sub->msn_MutualExclude = from_s->em_NewMenu.nm_MutualExclude;
  646.  
  647.             } else {
  648.                 return( FALSE );
  649.             }
  650.             }
  651.  
  652.         } else {
  653.             return( FALSE );
  654.         }
  655.         }
  656.  
  657.     } else {
  658.         return( FALSE );
  659.     }
  660.     }
  661.  
  662.     return( TRUE );
  663. }
  664. ///
  665. /// Screen
  666. ULONG ConvertScr( struct IE_Data *IE, GUIDATA *GuiInfo )
  667. {
  668.     IE->ScreenData->Tags[ SCRWIDTH    ] = GuiInfo->gui_Width;
  669.     IE->ScreenData->Tags[ SCRHEIGHT   ] = GuiInfo->gui_Height;
  670.     IE->ScreenData->Tags[ SCRDEPTH    ] = GuiInfo->gui_Depth;
  671.     IE->ScreenData->Tags[ SCRID       ] = GuiInfo->gui_DisplayID;
  672.     IE->ScreenData->Tags[ SCROVERSCAN ] = GuiInfo->gui_Overscan;
  673.     IE->ScreenData->Tags[ SCRAUTOSCROLL ] = ( GuiInfo->gui_Flags0 & GU0_AUTOSCROLL ) ? TRUE : FALSE;
  674.  
  675.     IE->ScreenData->NewFont.ta_YSize = GuiInfo->gui_Font.ta_YSize;
  676.     IE->ScreenData->NewFont.ta_Flags = GuiInfo->gui_Font.ta_Flags;
  677.     IE->ScreenData->NewFont.ta_Style = GuiInfo->gui_Font.ta_Style;
  678.     strcpy( IE->ScreenData->NewFont.ta_Name, GuiInfo->gui_Font.ta_Name );
  679.  
  680.     ( *IE->Functions->AddFont )( &GuiInfo->gui_Font );
  681.  
  682.     strcpy( IE->ScreenData->Title, GuiInfo->gui_ScreenTitle );
  683.  
  684.     IE->ScreenData->St_Left = GuiInfo->gui_Left;
  685.     IE->ScreenData->St_Top  = GuiInfo->gui_Top;
  686.  
  687.     if( GuiInfo->gui_Flags0 & GU0_PUBLIC )
  688.     IE->ScreenData->Type = PUBLICSCREEN;
  689.     else
  690.     IE->ScreenData->Type = CUSTOMSCREEN;
  691.  
  692.     memcpy( IE->ScreenData->DriPens, GuiInfo->gui_DriPens, 20 );
  693.     IE->ScreenData->DriPens[10] = GuiInfo->gui_MoreDriPens[0];
  694.     IE->ScreenData->DriPens[11] = GuiInfo->gui_MoreDriPens[1];
  695.  
  696.     #ifdef DEBUG
  697.     Printf( "ConvertScr() OK\n" );
  698.     #endif
  699.  
  700.     return( ConvertColors( IE, 1 << IE->ScreenData->Tags[ SCRDEPTH ], GuiInfo ));
  701. }
  702.  
  703. ULONG ConvertColors( struct IE_Data *IE, UWORD num, GUIDATA *GuiInfo )
  704. {
  705.     UWORD               c;
  706.     struct ColorSpec   *col;
  707.     ULONG               ret = LOADER_OK;
  708.  
  709.     if( GuiInfo->gui_Colors[0].ColorIndex == -1 )
  710.     return( LOADER_OK );
  711.  
  712.     if( IE->colortable )           // make sure to release it
  713.     FreeVec( IE->colortable );
  714.  
  715.     if( SysBase->LibNode.lib_Version >= 39 ) {  // Kick 3.0
  716.  
  717.     ULONG  *ptr;
  718.     if( ptr = IE->colortable = AllocVec(( num * 12 ) + 8, 0L )) {
  719.  
  720.         *ptr++ = num << 16;
  721.  
  722.         for( c = 0; c < num; c++ ) {
  723.  
  724.         col = &GuiInfo->gui_Colors[ c ];
  725.  
  726.         if( col->ColorIndex != -1 ) {
  727.             ULONG c3;
  728.  
  729.             // Now we MUST scale the color values from
  730.             // 4 bit per gun to 32 bit per gun
  731.  
  732.             c3 = (col->Red << 4) | col->Red;
  733.             c3 |= c3 << 8;
  734.             *ptr++ = c3 | ( c3 << 16 );
  735.  
  736.             c3 = (col->Green << 4) | col->Green;
  737.             c3 |= c3 << 8;
  738.             *ptr++ = c3 | ( c3 << 16 );
  739.  
  740.             c3 = (col->Blue << 4) | col->Blue;
  741.             c3 |= c3 << 8;
  742.             *ptr++ = c3 | ( c3 << 16 );
  743.  
  744.         } else {
  745.             c = num;
  746.         }
  747.  
  748.         }
  749.         *ptr = NULL;
  750.  
  751.     } else {
  752.         ret = LOADER_NOMEMORY;
  753.     }
  754.     } else {                             // Kick 2.0
  755.  
  756.     UWORD *ptr2;
  757.     if( ptr2 = IE->colortable = AllocVec( num + num + 2, 0L )) {
  758.  
  759.         *ptr2++ = num;
  760.  
  761.         for( c = 0; c < num; c ++ ) {
  762.  
  763.         col = &GuiInfo->gui_Colors[ c ];
  764.  
  765.         *ptr2++ = (col->Red << 8) | (col->Green << 4) | col->Blue;
  766.         }
  767.  
  768.     } else {
  769.         ret = LOADER_NOMEMORY;
  770.     }
  771.     }
  772.  
  773.     #ifdef DEBUG
  774.     Printf( "ConvertColors() OK\n" );
  775.     #endif
  776.  
  777.     return( ret );
  778. }
  779. ///
  780.  
  781. // Main routines
  782. /// LoadGUI
  783. ULONG LoadGUI( __A0 struct IE_Data *IE, __A1 UBYTE *Filename )
  784. {
  785.     APTR                    Chain;
  786.     ULONG                   ret;
  787.     struct WindowList       Windows;
  788.     GUIDATA                 GuiInfo;
  789.     struct ProjectWindow   *wnd;
  790.  
  791.     if(!( Chain = GetMemoryChain( 4096L )))
  792.     return( LOADER_NOMEMORY );
  793.  
  794.     NewList( &Windows );
  795.  
  796.     if( ret = GTX_LoadGUI( Chain, Filename,
  797.                RG_WindowList, &Windows,
  798.                RG_GUI, &GuiInfo,
  799.                TAG_END )) {
  800.  
  801.     switch( ret ) {
  802.         case ERROR_NOMEM:
  803.         ret = LOADER_NOMEMORY;
  804.         break;
  805.  
  806.         case ERROR_OPEN:
  807.         case ERROR_READ:
  808.         case ERROR_WRITE:
  809.         case ERROR_PARSE:
  810.         case ERROR_PACKER:
  811.         case ERROR_PPLIB:
  812.         ret = LOADER_IOERR;
  813.         break;
  814.  
  815.         case ERROR_NOTGUIFILE:
  816.         ret = LOADER_UNKNOWN;
  817.         break;
  818.     }
  819.  
  820.     } else {
  821.  
  822.     for( wnd = Windows.wl_First; wnd->pw_Next; wnd = wnd->pw_Next ) {
  823.  
  824.         if(!( IE->win_info = ConvertWin( IE, wnd ))) {
  825.         ret = LOADER_NOMEMORY;
  826.         goto done;
  827.         }
  828.     }
  829.  
  830.     ret = ConvertScr( IE, &GuiInfo );
  831.  
  832. done:
  833.  
  834.     GTX_FreeWindows( Chain, &Windows );
  835.     }
  836.  
  837.     FreeMemoryChain( Chain, TRUE );
  838.  
  839.     return( ret );
  840. }
  841. ///
  842.  
  843. // These routines are not supported by this module since they need
  844. // some *private* functions of gadtoolsbox.library... But if you can
  845. // implement them, well, you'd do a great thing! ;-)
  846. /// LoadWindows
  847. ULONG LoadWindows( __A0 struct IE_Data *IE, __A1 UBYTE *Filename )
  848. {
  849.     return( LOADER_NOTSUPPORTED );
  850. }
  851. ///
  852. /// LoadGadgets
  853. ULONG LoadGadgets( __A0 struct IE_Data *IE, __A1 UBYTE *Filename )
  854. {
  855.     return( LOADER_NOTSUPPORTED );
  856. }
  857. ///
  858. /// LoadScreen
  859. ULONG LoadScreen( __A0 struct IE_Data *IE, __A1 UBYTE *Filename )
  860. {
  861.     return( LOADER_NOTSUPPORTED );
  862. }
  863. ///
  864.  
  865.