home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / lib / mariner / src / xptabnav.c < prev   
Encoding:
C/C++ Source or Header  |  1998-04-08  |  4.9 KB  |  199 lines

  1. /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  2.  *
  3.  * The contents of this file are subject to the Netscape Public License
  4.  * Version 1.0 (the "NPL"); you may not use this file except in
  5.  * compliance with the NPL.  You may obtain a copy of the NPL at
  6.  * http://www.mozilla.org/NPL/
  7.  *
  8.  * Software distributed under the NPL is distributed on an "AS IS" basis,
  9.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
  10.  * for the specific language governing rights and limitations under the
  11.  * NPL.
  12.  *
  13.  * The Initial Developer of this code under the NPL is Netscape
  14.  * Communications Corporation.  Portions created by Netscape are
  15.  * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
  16.  * Reserved.
  17.  */
  18. /* 
  19.    xptabnav.c --- an API for XP HTML area tabbing.
  20.    Created: Chris Toshok <toshok@netscape.com>, 6-Nov-1997.
  21.  */
  22.  
  23.  
  24. #include "xptabnav.h"
  25. #include "xpassert.h"
  26. #include "structs.h"
  27. #include "proto.h"
  28. #include "client.h"
  29. #include "fe_proto.h"
  30. #include "xp_rect.h"
  31. #include "layers.h"
  32.  
  33. #define FOCUS_DATA(context) (context->tab_focus_data)
  34. #define FOCUS_ELEMENT(context) (FOCUS_DATA(context)->pElement)
  35. #define FOCUS_INDEX(context) (FOCUS_DATA(context)->mapAreaIndex)
  36. #define FOCUS_ANCHOR(context) (FOCUS_DATA(context)->pAnchor)
  37.  
  38. void
  39. XPTAB_SetFocusElement(MWContext *context,
  40.                       LO_Element *element)
  41. {
  42.   LO_TabFocusData data;
  43.  
  44.   XP_ASSERT(FOCUS_DATA(context));
  45.   if (!FOCUS_DATA(context)) return;
  46.  
  47.   data.pElement = element;
  48.   data.mapAreaIndex = 0;
  49.   data.pAnchor = 0;
  50.   
  51.   if (LO_isTabableElement(context, &data))
  52.     *FOCUS_DATA(context) = data;
  53. }
  54.  
  55. LO_Element*
  56. XPTAB_GetFocusElement(MWContext *context)
  57. {
  58.   XP_ASSERT(FOCUS_DATA(context));
  59.   if (!FOCUS_DATA(context)) return NULL;
  60.  
  61.   return FOCUS_ELEMENT(context);
  62. }
  63.  
  64. int32
  65. XPTAB_GetFocusMapAreaIndex(MWContext *context)
  66. {
  67.   XP_ASSERT(FOCUS_DATA(context));
  68.   if (!FOCUS_DATA(context)) return -1;
  69.  
  70.   return FOCUS_INDEX(context);
  71. }
  72.  
  73. void
  74. XPTAB_GetFocusMapArea(MWContext *context,
  75.               lo_MapAreaRec **map_area)
  76. {
  77.   *map_area = NULL;
  78.  
  79.   XP_ASSERT(FOCUS_DATA(context));
  80.   if (!FOCUS_DATA(context)) return;
  81.  
  82.   if (FOCUS_ELEMENT(context)->type == LO_IMAGE
  83.       && FOCUS_INDEX(context))
  84.     *map_area = LO_getTabableMapArea(context,
  85.                      (LO_ImageStruct*)FOCUS_ELEMENT(context),
  86.                      FOCUS_INDEX(context));
  87. }
  88.  
  89. void
  90. XPTAB_InitTabData(MWContext *context)
  91. {
  92.   printf ("In XPTAB_InitTabData\n");
  93.   FOCUS_DATA(context) = XP_NEW_ZAP(LO_TabFocusData);
  94. }
  95.  
  96. void
  97. XPTAB_DestroyTabData(MWContext *context)
  98. {
  99.   XP_ASSERT(FOCUS_DATA(context));
  100.   if (!FOCUS_DATA(context)) return;
  101.  
  102.   XP_FREE(FOCUS_DATA(context));
  103. }
  104.  
  105. void
  106. XPTAB_ClearTabFocus(MWContext *context)
  107. {
  108.   XP_ASSERT(FOCUS_DATA(context));
  109.   if (!FOCUS_DATA(context)) return;
  110.  
  111.   XP_MEMSET(FOCUS_DATA(context), 0, sizeof(LO_TabFocusData));
  112. }
  113.  
  114. static Bool
  115. xptab_MoveFocus(MWContext *context, int forward)
  116. {
  117.   Bool tabbed;
  118.   LO_TabFocusData old_focus_data;
  119.  
  120.   XP_ASSERT(FOCUS_DATA(context));
  121.   if (!FOCUS_DATA(context)) return FALSE;
  122.  
  123.   old_focus_data = *FOCUS_DATA(context);
  124.  
  125.   tabbed = LO_getNextTabableElement(context, FOCUS_DATA(context), forward);
  126.   
  127.   /* if is the same element, just return FALSE. */
  128.   if (old_focus_data.pElement == FOCUS_ELEMENT(context)
  129.       && old_focus_data.mapAreaIndex == FOCUS_INDEX(context))
  130.     return FALSE;
  131.   
  132.   if (tabbed) /* if we actually tabbed someplace. */
  133.     {
  134.       if (old_focus_data.pElement)
  135.     if (old_focus_data.pElement->type == LO_FORM_ELE)
  136.       {
  137.         FE_BlurInputElement(context, old_focus_data.pElement);
  138.       }
  139.     else
  140.       {
  141.         /* erase the old feedback */
  142.         XP_Rect rect;
  143.  
  144.         rect.left = old_focus_data.pElement->lo_any.x;
  145.         rect.top = old_focus_data.pElement->lo_any.y;
  146.         rect.right = (old_focus_data.pElement->lo_any.x +
  147.               old_focus_data.pElement->lo_any.width);
  148.         rect.bottom = (old_focus_data.pElement->lo_any.y +
  149.                old_focus_data.pElement->lo_any.height);
  150.  
  151.         CL_UpdateDocumentRect(context->compositor, &rect, PR_FALSE);
  152.       }
  153.  
  154.       {
  155.     /* scroll to make the element visible. */
  156.       }
  157.       
  158.       if (FOCUS_ELEMENT(context)->type == LO_FORM_ELE)
  159.     {
  160.       FE_FocusInputElement(context, FOCUS_ELEMENT(context));
  161.     }
  162.       else
  163.     {
  164.       FE_FocusInputElement(context, NULL);
  165.       
  166.       /* display a feedback rectangle if it's not a form element */
  167.       FE_DisplayFeedback(context, FE_VIEW, FOCUS_ELEMENT(context));
  168.     }
  169.       
  170.       if (FOCUS_ANCHOR(context))
  171.     FE_Progress(context, (char*)FOCUS_ANCHOR(context)->anchor);
  172.     }
  173.   
  174.   return tabbed;
  175. }
  176.  
  177. Bool
  178. XPTAB_TabToNextElement(MWContext *context)
  179. {
  180.   return xptab_MoveFocus(context, TRUE);
  181. }
  182.  
  183. Bool
  184. XPTAB_TabToPrevElement(MWContext *context)
  185. {
  186.   return xptab_MoveFocus(context, FALSE);
  187. }
  188.  
  189. Bool
  190. XPTAB_TabToNextFormElement(MWContext *context)
  191. {
  192. }
  193.  
  194. Bool
  195. XPTAB_TabToPrevFormElement(MWContext *context)
  196. {
  197. }
  198.  
  199.