home *** CD-ROM | disk | FTP | other *** search
/ BCI NET 2 / BCI NET 2.iso / archives / programming / source / term43-source.lha / Extras / Source / gtlayout-Source.lha / LT_CreateHandle.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-01-25  |  6.2 KB  |  236 lines

  1. /*  GadTools layout toolkit
  2. **
  3. **  Copyright © 1993-1994 by Olaf `Olsen' Barthel
  4. **  Freely distributable.
  5. */
  6.  
  7. #include "gtlayout_global.h"
  8.  
  9. LayoutHandle * LIBENT
  10. LT_CreateHandle(REG(a0) struct Screen *Screen,REG(a1) struct TextAttr *Font)
  11. {
  12.     return(LT_CreateHandleTags(Screen,
  13.         LH_Font,    Font,
  14.     TAG_DONE));
  15. }
  16.  
  17. LayoutHandle * __stdargs
  18. LT_CreateHandleTags(struct Screen *Screen,...)
  19. {
  20.     LayoutHandle    *Handle;
  21.     va_list      VarArgs;
  22.  
  23.     va_start(VarArgs,Screen);
  24.     Handle = LT_CreateHandleTagList(Screen,(struct TagItem *)VarArgs);
  25.     va_end(VarArgs);
  26.  
  27.     return(Handle);
  28. }
  29.  
  30. LayoutHandle * LIBENT
  31. LT_CreateHandleTagList(REG(a0) struct Screen *Screen,REG(a1) struct TagItem *TagList)
  32. {
  33.     LayoutHandle    *Handle;
  34.     struct Screen    *PubScreen;
  35.     struct TextAttr *textAttr;
  36.  
  37. #ifdef DO_PICKSHORTCUTS
  38.     ObtainSemaphore(<P_KeySemaphore);
  39.  
  40.     if(!LTP_KeysInitialized)
  41.     {
  42.         UBYTE          mapBuffer[2 * 3];
  43.         UBYTE          remapBuffer[10];
  44.         LONG          i;
  45.         struct InputEvent event;
  46.  
  47.         for(i = 0 ; i < 256; i++)
  48.         {
  49.             if((i > ' ' && i < 127) || i > 160)
  50.             {
  51.                 remapBuffer[0] = i;
  52.                 remapBuffer[1] = 0;
  53.  
  54.                 if(MapANSI(remapBuffer,1,mapBuffer,3,NULL) == 1)
  55.                 {
  56.                     if(!(mapBuffer[1] & ~QUALIFIER_SHIFT))
  57.                     {
  58.                         event . ie_NextEvent        = NULL;
  59.                         event . ie_Class        = IECLASS_RAWKEY;
  60.                         event . ie_SubClass        = 0;
  61.                         event . ie_Code         = mapBuffer[0];
  62.                         event . ie_Qualifier        = mapBuffer[1] & ~QUALIFIER_SHIFT;
  63.                         event . ie_position . ie_addr    = NULL;
  64.  
  65.                         if(MapRawKey(&event,remapBuffer,10,NULL) == 1)
  66.                             LTP_Keys[0][i] = remapBuffer[0];
  67.  
  68.                         event . ie_NextEvent        = NULL;
  69.                         event . ie_Class        = IECLASS_RAWKEY;
  70.                         event . ie_SubClass        = 0;
  71.                         event . ie_Code         = mapBuffer[0];
  72.                         event . ie_Qualifier        = mapBuffer[1] | QUALIFIER_SHIFT;
  73.                         event . ie_position . ie_addr    = NULL;
  74.  
  75.                         if(MapRawKey(&event,remapBuffer,10,NULL) == 1)
  76.                             LTP_Keys[1][i] = remapBuffer[0];
  77.                     }
  78.                 }
  79.             }
  80.         }
  81.  
  82.         LTP_KeysInitialized = TRUE;
  83.     }
  84.  
  85.     ReleaseSemaphore(<P_KeySemaphore);
  86. #endif    /* DO_PICKSHORTCUTS */
  87.  
  88.     textAttr = (struct TextAttr *)GetTagData(LH_Font,NULL,TagList);
  89.  
  90.     if(!Screen)
  91.     {
  92.         if(!(PubScreen = LockPubScreen(NULL)))
  93.             return(NULL);
  94.         else
  95.             Screen = PubScreen;
  96.     }
  97.     else
  98.         PubScreen = NULL;
  99.  
  100.     if(Handle = AllocMem(sizeof(LayoutHandle),MEMF_ANY | MEMF_PUBLIC | MEMF_CLEAR))
  101.     {
  102.         Handle -> Screen    = Screen;
  103.         Handle -> PubScreen    = PubScreen;
  104.         Handle -> AutoActivate    = GetTagData(LH_AutoActivate,FALSE,TagList);
  105.         Handle -> LocaleHook    = (struct Hook *)GetTagData(LH_LocaleHook,NULL,TagList);
  106.  
  107.         Handle -> Parent    = (struct Window *)GetTagData(LH_Parent,NULL,TagList);
  108.         Handle -> BlockParent    = GetTagData(LH_BlockParent,FALSE,TagList);
  109.         Handle -> Expand    = GetTagData(LH_Expand,FALSE,TagList);
  110.         Handle -> ExitFlush    = GetTagData(LH_ExitFlush,TRUE,TagList);
  111.         Handle -> UserData    = (APTR)GetTagData(LH_UserData,TRUE,TagList);
  112.  
  113. #ifdef DO_CLONING
  114.         Handle -> CloningPermitted    = GetTagData(LH_CloningPermitted,TRUE,TagList);
  115.         Handle -> SimpleClone        = GetTagData(LH_SimpleClone,FALSE,TagList);
  116.         Handle -> ExactClone        = GetTagData(LH_ExactClone,FALSE,TagList);
  117.  
  118.         if(Handle -> ExactClone)
  119.             Handle -> SimpleClone = FALSE;
  120. #endif
  121.  
  122. #ifdef DO_FRACTION_KIND
  123.         Handle -> FracEditHook . h_Entry    = (HOOKFUNC)LTP_FracEditRoutine;
  124.         Handle -> FracEditHook . h_Data     = Handle;
  125. #endif
  126.  
  127. #ifdef DO_PASSWORD_KIND
  128.         Handle -> PasswordEditHook . h_Entry    = (HOOKFUNC)LTP_PasswordEditRoutine;
  129.         Handle -> PasswordEditHook . h_Data    = Handle;
  130. #endif
  131.  
  132.         Handle -> DefaultEditHook . h_Entry    = (HOOKFUNC)LTP_DefaultEditRoutine;
  133.         Handle -> DefaultEditHook . h_Data    = Handle;
  134.  
  135.         Handle -> BackfillHook . h_Entry    = (HOOKFUNC)LTP_BackfillRoutine;
  136.         Handle -> BackfillHook . h_Data     = Handle;
  137.  
  138.         Handle -> StandardEditHook = (struct Hook *)GetTagData(LH_EditHook,(ULONG)&Handle -> DefaultEditHook,TagList);
  139.  
  140. #ifdef DO_HEXHOOK
  141.         Handle -> HexEditHook . h_Entry     = (HOOKFUNC)LTP_HexEditRoutine;
  142.         Handle -> HexEditHook . h_Data        = Handle;
  143. #endif
  144.         if(Handle -> Pool = AsmCreatePool(MEMF_PUBLIC | MEMF_ANY | MEMF_CLEAR,1024,1024,SysBase))
  145.         {
  146.             if(Handle -> DrawInfo = GetScreenDrawInfo(Screen))
  147.             {
  148.                 LONG i;
  149.  
  150.                 Handle -> TextPen    = Handle -> DrawInfo -> dri_Pens[TEXTPEN];
  151.                 Handle -> BackgroundPen = Handle -> DrawInfo -> dri_Pens[BACKGROUNDPEN];
  152.                 Handle -> ShinePen    = Handle -> DrawInfo -> dri_Pens[SHINEPEN];
  153.                 Handle -> ShadowPen    = Handle -> DrawInfo -> dri_Pens[SHADOWPEN];
  154.                 Handle -> AspectX    = Handle -> DrawInfo -> dri_Resolution . X;
  155.                 Handle -> AspectY    = Handle -> DrawInfo -> dri_Resolution . Y;
  156.  
  157.                 if(V39 && FindTagItem(LH_MenuGlyphs,TagList))
  158.                 {
  159.                     LONG Size,FontHeight = Handle -> DrawInfo -> dri_Font -> tf_Baseline + 2;
  160.  
  161.                     if(Screen -> Flags & SCREENHIRES)
  162.                         Size = SYSISIZE_MEDRES;
  163.                     else
  164.                         Size = SYSISIZE_LOWRES;
  165.  
  166.                     if(Handle -> AmigaGlyph = NewObject(NULL,SYSICLASS,
  167.                         SYSIA_DrawInfo, Handle -> DrawInfo,
  168.                         SYSIA_Size,    Size,
  169.                         SYSIA_Which,    AMIGAKEY,
  170.                         IA_Left,    0,
  171.                         LA_Top,     0,
  172.                         IA_Width,    (FontHeight * 3 * Handle -> AspectY) / (2 * Handle -> AspectX),
  173.                         IA_Height,    FontHeight,
  174.                     TAG_DONE))
  175.                     {
  176.                         if(!(Handle -> CheckGlyph = NewObject(NULL,SYSICLASS,
  177.                             SYSIA_DrawInfo, Handle -> DrawInfo,
  178.                             SYSIA_Size,    Size,
  179.                             SYSIA_Which,    MENUCHECK,
  180.                             IA_Left,    0,
  181.                             LA_Top,     0,
  182.                             IA_Width,    (FontHeight * Handle -> AspectY) / Handle -> AspectX,
  183.                             IA_Height,    FontHeight,
  184.                         TAG_DONE)))
  185.                         {
  186.                             DisposeObject(Handle -> AmigaGlyph);
  187.  
  188.                             Handle -> AmigaGlyph = NULL;
  189.                         }
  190.                     }
  191.                 }
  192.  
  193.                 for(i = 0 ; i < Handle -> DrawInfo -> dri_NumPens ; i++)
  194.                 {
  195.                     if(Handle -> DrawInfo -> dri_Pens[i] > Handle -> MaxPen)
  196.                         Handle -> MaxPen = Handle -> DrawInfo -> dri_Pens[i];
  197.                 }
  198.  
  199.                 if(Handle -> VisualInfo = GetVisualInfoA(Screen,NULL))
  200.                 {
  201.                     if(textAttr)
  202.                         Handle -> InitialTextAttr = textAttr;
  203.  
  204.                     InitRastPort(&Handle -> RPort);
  205.  
  206.                     if(LTP_GlyphSetup(Handle,textAttr))
  207.                     {
  208. #ifdef DO_PICKSHORTCUTS
  209.                         memset(Handle -> Keys,TRUE,256);
  210.  
  211.                         for(i = 0 ; i < 256 ; i++)
  212.                         {
  213.                             if(i != 32 && i != 160)
  214.                             {
  215.                                 if(LTP_Keys[0][i])
  216.                                     Handle -> Keys[LTP_Keys[0][i]] = FALSE;
  217.  
  218.                                 if(LTP_Keys[1][i])
  219.                                     Handle -> Keys[LTP_Keys[1][i]] = FALSE;
  220.                             }
  221.                         }
  222. #endif
  223.                         return(Handle);
  224.                     }
  225.                 }
  226.             }
  227.         }
  228.  
  229.         LT_DeleteHandle(Handle);
  230.     }
  231.     else
  232.         UnlockPubScreen(NULL,PubScreen);
  233.  
  234.     return(NULL);
  235. }
  236.