home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / lib / mariner / src / xpform.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  9.2 KB  |  395 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.    xpform.c --- an API for accessing form element information.
  20.    Created: Chris Toshok <toshok@netscape.com>, 29-Oct-1997.
  21.  */
  22.  
  23.  
  24. #include "xpform.h"
  25. #include "xpassert.h"
  26.  
  27. LO_FormElementData*
  28. XP_GetFormElementData(LO_FormElementStruct *form)
  29. {
  30.   return form->element_data;
  31. }
  32.  
  33. LO_TextAttr*
  34. XP_GetFormTextAttr(LO_FormElementStruct *form)
  35. {
  36.   return form->text_attr;
  37. }
  38.  
  39. uint16
  40. XP_GetFormEleAttrmask(LO_FormElementStruct *form)
  41. {
  42.   return form->ele_attrmask;
  43. }
  44.  
  45. int32   
  46. XP_FormGetType(LO_FormElementData *form)
  47. {
  48.   return form->type;
  49. }
  50.  
  51. void    
  52. XP_FormSetFEData(LO_FormElementData *form, 
  53.                  void* fe_data)
  54. {
  55.   form->ele_minimal.FE_Data = fe_data;
  56. }
  57.  
  58.  
  59. void*   
  60. XP_FormGetFEData(LO_FormElementData *form)
  61. {
  62.   return form->ele_minimal.FE_Data;
  63. }
  64.  
  65. /* Methods that work for Hidden, Submit, Reset, Button, and Readonly
  66.    form elements. */
  67. PA_Block
  68. XP_FormGetValue(LO_FormElementData *form)
  69. {
  70.   XP_ASSERT(form->type == FORM_TYPE_HIDDEN
  71.             || form->type == FORM_TYPE_SUBMIT
  72.             || form->type == FORM_TYPE_RESET
  73.             || form->type == FORM_TYPE_BUTTON
  74.             || form->type == FORM_TYPE_READONLY);
  75.  
  76.   return form->ele_minimal.value;
  77. }
  78.  
  79. Bool
  80. XP_FormGetDisabled(LO_FormElementData *form)
  81. {
  82.   XP_ASSERT(form->type == FORM_TYPE_SELECT_ONE
  83.             || form->type == FORM_TYPE_SELECT_MULT
  84.             || form->type == FORM_TYPE_TEXT
  85.             || form->type == FORM_TYPE_TEXTAREA
  86.             || form->type == FORM_TYPE_RADIO
  87.             || form->type == FORM_TYPE_CHECKBOX
  88.             || form->type == FORM_TYPE_SUBMIT
  89.             || form->type == FORM_TYPE_RESET
  90.             || form->type == FORM_TYPE_BUTTON
  91.             || form->type == FORM_TYPE_READONLY);
  92.  
  93.   if (form->type == FORM_TYPE_SELECT_ONE
  94.             || form->type == FORM_TYPE_SELECT_MULT
  95.             || form->type == FORM_TYPE_TEXT
  96.             || form->type == FORM_TYPE_TEXTAREA
  97.             || form->type == FORM_TYPE_RADIO
  98.             || form->type == FORM_TYPE_CHECKBOX
  99.             || form->type == FORM_TYPE_SUBMIT
  100.             || form->type == FORM_TYPE_RESET
  101.             || form->type == FORM_TYPE_BUTTON
  102.             || form->type == FORM_TYPE_READONLY)
  103.     return form->ele_minimal.disabled;
  104.   else
  105.     return FALSE;
  106. }
  107.  
  108. /* Methods that work on text or text area form elements */
  109. PA_Block
  110. XP_FormGetDefaultText(LO_FormElementData *form)
  111. {
  112.   XP_ASSERT(form->type == FORM_TYPE_TEXT
  113.             || form->type == FORM_TYPE_TEXTAREA
  114.             || form->type == FORM_TYPE_PASSWORD
  115.             || form->type == FORM_TYPE_READONLY
  116.             || form->type == FORM_TYPE_FILE);
  117.   
  118.   switch(form->type)
  119.     {
  120.     case FORM_TYPE_TEXT:
  121.     case FORM_TYPE_PASSWORD:
  122.     case FORM_TYPE_FILE:
  123.     case FORM_TYPE_READONLY:
  124.       return form->ele_text.default_text;
  125.     case FORM_TYPE_TEXTAREA:
  126.       return form->ele_textarea.default_text;
  127.     default:
  128.       return NULL;
  129.     }
  130. }
  131.  
  132. PA_Block
  133. XP_FormGetCurrentText(LO_FormElementData *form)
  134. {
  135.   XP_ASSERT(form->type == FORM_TYPE_TEXT
  136.             || form->type == FORM_TYPE_TEXTAREA
  137.             || form->type == FORM_TYPE_PASSWORD
  138.             || form->type == FORM_TYPE_READONLY
  139.             || form->type == FORM_TYPE_FILE);
  140.   
  141.   switch(form->type)
  142.     {
  143.     case FORM_TYPE_TEXT:
  144.     case FORM_TYPE_PASSWORD:
  145.     case FORM_TYPE_FILE:
  146.     case FORM_TYPE_READONLY:
  147.       return form->ele_text.current_text;
  148.     case FORM_TYPE_TEXTAREA:
  149.       return form->ele_textarea.current_text;
  150.     default:
  151.       return NULL;
  152.     }
  153. }
  154.  
  155. void    
  156. XP_FormSetCurrentText(LO_FormElementData *form,
  157.                       PA_Block current_text)
  158. {
  159.   XP_ASSERT(form->type == FORM_TYPE_TEXT
  160.             || form->type == FORM_TYPE_TEXTAREA
  161.             || form->type == FORM_TYPE_PASSWORD
  162.             || form->type == FORM_TYPE_READONLY
  163.             || form->type == FORM_TYPE_FILE);
  164.   
  165.   switch(form->type)
  166.     {
  167.     case FORM_TYPE_TEXT:
  168.     case FORM_TYPE_PASSWORD:
  169.     case FORM_TYPE_FILE:
  170.     case FORM_TYPE_READONLY:
  171.       form->ele_text.current_text = current_text;
  172.       break;
  173.     case FORM_TYPE_TEXTAREA:
  174.       form->ele_textarea.current_text = current_text;
  175.       break;
  176.     }
  177. }
  178.  
  179. Bool
  180. XP_FormGetReadonly(LO_FormElementData *form)
  181. {
  182.   XP_ASSERT(form->type == FORM_TYPE_TEXT
  183.             || form->type == FORM_TYPE_TEXTAREA
  184.             || form->type == FORM_TYPE_PASSWORD
  185.             || form->type == FORM_TYPE_READONLY);
  186.   
  187.   switch(form->type)
  188.     {
  189.     case FORM_TYPE_TEXT:
  190.     case FORM_TYPE_PASSWORD:
  191.     case FORM_TYPE_READONLY:
  192.       return form->ele_text.readonly;
  193.     case FORM_TYPE_TEXTAREA:
  194.       return form->ele_textarea.readonly;
  195.     default:
  196.       return FALSE;
  197.     }
  198. }
  199.  
  200. /* text specific methods. */
  201. int32   
  202. XP_FormTextGetSize(LO_FormElementData *form)
  203. {
  204.   XP_ASSERT(form->type == FORM_TYPE_TEXT
  205.             || form->type == FORM_TYPE_PASSWORD
  206.             || form->type == FORM_TYPE_READONLY
  207.             || form->type == FORM_TYPE_FILE);
  208.   
  209.   return form->ele_text.size;
  210. }
  211.  
  212. int32   
  213. XP_FormTextGetMaxSize(LO_FormElementData *form)
  214. {
  215.   XP_ASSERT(form->type == FORM_TYPE_TEXT
  216.             || form->type == FORM_TYPE_PASSWORD
  217.             || form->type == FORM_TYPE_READONLY
  218.             || form->type == FORM_TYPE_FILE);
  219.   
  220.   return form->ele_text.max_size;
  221. }
  222.  
  223. /* text area specific methods. */
  224. void    
  225. XP_FormTextAreaGetDimensions(LO_FormElementData *form,
  226.                              int32 *rows, 
  227.                              int32 *cols)
  228. {
  229.   XP_ASSERT(form->type == FORM_TYPE_TEXTAREA);
  230.  
  231.   if (rows)
  232.     *rows = form->ele_textarea.rows;
  233.   if (cols)
  234.     *cols = form->ele_textarea.cols;
  235. }
  236.  
  237. uint8   
  238. XP_FormTextAreaGetAutowrap(LO_FormElementData *form)
  239. {
  240.   XP_ASSERT(form->type == FORM_TYPE_TEXTAREA);
  241.  
  242.   return form->ele_textarea.auto_wrap;
  243. }
  244.  
  245. /* radio/checkbox specific methods */
  246. Bool    
  247. XP_FormGetDefaultToggled(LO_FormElementData *form)
  248. {
  249.   XP_ASSERT(form->type == FORM_TYPE_RADIO
  250.             || form->type == FORM_TYPE_CHECKBOX);
  251.  
  252.   return form->ele_toggle.default_toggle;
  253. }
  254.  
  255. Bool    
  256. XP_FormGetElementToggled(LO_FormElementData *form)
  257. {
  258.   XP_ASSERT(form->type == FORM_TYPE_RADIO
  259.             || form->type == FORM_TYPE_CHECKBOX);
  260.  
  261.   return form->ele_toggle.toggled;
  262. }
  263.  
  264. void    
  265. XP_FormSetElementToggled(LO_FormElementData *form,
  266.                          Bool toggled)
  267. {
  268.   XP_ASSERT(form->type == FORM_TYPE_RADIO
  269.             || form->type == FORM_TYPE_CHECKBOX);
  270.  
  271.   form->ele_toggle.toggled = toggled;
  272. }
  273.  
  274. /* select specific methods */
  275. int32   
  276. XP_FormSelectGetSize(LO_FormElementData *form)
  277. {
  278.   XP_ASSERT(form->type == FORM_TYPE_SELECT_ONE
  279.             || form->type == FORM_TYPE_SELECT_MULT);
  280.  
  281.   return form->ele_select.size;
  282. }
  283.  
  284. Bool    
  285. XP_FormSelectGetMultiple(LO_FormElementData *form)
  286. {
  287.   XP_ASSERT(form->type == FORM_TYPE_SELECT_ONE
  288.             || form->type == FORM_TYPE_SELECT_MULT);
  289.  
  290.   return form->ele_select.multiple;
  291. }
  292.  
  293. Bool    
  294. XP_FormSelectGetOptionsValid(LO_FormElementData *form) /* XXX ? */
  295. {
  296.   XP_ASSERT(form->type == FORM_TYPE_SELECT_ONE
  297.             || form->type == FORM_TYPE_SELECT_MULT);
  298.  
  299.   return form->ele_select.options_valid;
  300. }
  301.  
  302. int32   
  303. XP_FormSelectGetOptionsCount(LO_FormElementData *form)
  304. {
  305.   XP_ASSERT(form->type == FORM_TYPE_SELECT_ONE
  306.             || form->type == FORM_TYPE_SELECT_MULT);
  307.  
  308.   return form->ele_select.option_cnt;
  309. }
  310.  
  311. lo_FormElementOptionData*
  312. XP_FormSelectGetOption(LO_FormElementData *form,
  313.                        int option_index)
  314. {
  315.   XP_ASSERT((form->type == FORM_TYPE_SELECT_ONE
  316.              || form->type == FORM_TYPE_SELECT_MULT)
  317.             && option_index >= 0
  318.             && option_index < form->ele_select.option_cnt);
  319.   
  320.   return &((lo_FormElementOptionData*)form->ele_select.options)[option_index];
  321. }
  322.  
  323. /* option specific methods */
  324. Bool    
  325. XP_FormOptionGetDefaultSelected(lo_FormElementOptionData *option_element)
  326. {
  327.   return option_element->def_selected;
  328. }
  329.  
  330. Bool    
  331. XP_FormOptionGetSelected(lo_FormElementOptionData *option_element)
  332. {
  333.   return option_element->selected;
  334. }
  335.  
  336. void    
  337. XP_FormOptionSetSelected(lo_FormElementOptionData *option_element, 
  338.                          Bool selected)
  339. {
  340.   option_element->selected = selected;
  341. }
  342.  
  343. /* object */
  344. LO_JavaAppStruct*   
  345. XP_FormObjectGetJavaApp(LO_FormElementData *form)
  346. {
  347.   XP_ASSERT(form->type == FORM_TYPE_OBJECT);
  348.  
  349.   return form->ele_object.object;
  350. }
  351.  
  352. void    
  353. XP_FormObjectSetJavaApp(LO_FormElementData *form,
  354.                         LO_JavaAppStruct *java_app)
  355. {
  356.   XP_ASSERT(form->type == FORM_TYPE_OBJECT);
  357.  
  358.   form->ele_object.object = java_app;
  359. }
  360.  
  361. /* keygen */
  362. PA_Block    
  363. XP_FormKeygenGetChallenge(LO_FormElementData *form)
  364. {
  365.   XP_ASSERT(form->type == FORM_TYPE_KEYGEN);
  366.  
  367.   return form->ele_keygen.challenge;
  368. }
  369.  
  370. PA_Block    
  371. XP_FormKeygenGetKeytype(LO_FormElementData *form)
  372. {
  373.   XP_ASSERT(form->type == FORM_TYPE_KEYGEN);
  374.  
  375.   return form->ele_keygen.key_type;
  376. }
  377.  
  378. PA_Block    
  379. XP_FormKeygenGetPQG(LO_FormElementData *form)
  380. {
  381.   XP_ASSERT(form->type == FORM_TYPE_KEYGEN);
  382.  
  383.   return form->ele_keygen.pqg;
  384. }
  385.  
  386. char*       
  387. XP_FormKeygenGetValueStr(LO_FormElementData *form)
  388. {
  389.   XP_ASSERT(form->type == FORM_TYPE_KEYGEN);
  390.  
  391.   return form->ele_keygen.value_str;
  392. }
  393.  
  394. /* setter routines? */
  395.