/// <summary> /// Gets the form. /// </summary> /// <param name="formnode">The node of the form.</param> /// <returns></returns> private ODFForm CreateForm(XmlNode formnode) { ODFForm form = null; try { if (formnode.Name == "form:form") { if (this._debugMode) this.LogNode(formnode, "Log form node before"); //Create a new ODFForm ///////////TODO. Fix for child forms! form = new ODFForm(formnode.CloneNode(true), this._document); form.SuppressControlEvents(); foreach(XmlNode nodeChild in form.Node.ChildNodes) { switch (nodeChild.Name) { case "form:form": if (nodeChild.ParentNode==form.Node) { ODFForm frmchild = CreateForm(nodeChild); if (frmchild != null) { form.ChildForms.Add(frmchild); } form.Node.RemoveChild(nodeChild); } break; case "form:properties": break; case "form:button": if (nodeChild.ParentNode==form.Node) { ODFButton button = new ODFButton(form, nodeChild); button.FixPropertyCollection(); form.Controls.Add(button); } break; case "form:listbox": if (nodeChild.ParentNode==form.Node) { ODFListBox listbox = new ODFListBox(form, nodeChild); listbox.FixPropertyCollection(); listbox.FixOptionCollection(); form.Controls.Add(listbox); } break; case "form:combobox": if (nodeChild.ParentNode==form.Node) { ODFComboBox combobox = new ODFComboBox(form, nodeChild); combobox.FixPropertyCollection(); combobox.FixItemCollection(); form.Controls.Add(combobox); } break; case "form:textarea": if (nodeChild.ParentNode==form.Node) { ODFTextArea text = new ODFTextArea(form, nodeChild); text.FixPropertyCollection(); form.Controls.Add(text); } break; case "form:frame": if (nodeChild.ParentNode==form.Node) { ODFFrame frm = new ODFFrame(form, nodeChild); frm.FixPropertyCollection(); form.Controls.Add(frm); } break; case "form:file": if (nodeChild.ParentNode==form.Node) { ODFFile file = new ODFFile(form, nodeChild); file.FixPropertyCollection(); form.Controls.Add(file); } break; case "form:hidden": if (nodeChild.ParentNode==form.Node) { ODFHidden hidden = new ODFHidden(form, nodeChild); hidden.FixPropertyCollection(); form.Controls.Add(hidden); } break; case "form:checkbox": if (nodeChild.ParentNode==form.Node) { ODFCheckBox cb = new ODFCheckBox(form, nodeChild); cb.FixPropertyCollection(); form.Controls.Add(cb); } break; case "form:radio": if (nodeChild.ParentNode==form.Node) { ODFRadioButton rb = new ODFRadioButton(form, nodeChild); rb.FixPropertyCollection(); form.Controls.Add(rb); } break; case "form:formatted-text": if (nodeChild.ParentNode==form.Node) { ODFFormattedText text = new ODFFormattedText(form, nodeChild); text.FixPropertyCollection(); form.Controls.Add(text); } break; case "form:value-range": if (nodeChild.ParentNode==form.Node) { ODFValueRange vr = new ODFValueRange(form, nodeChild); vr.FixPropertyCollection(); form.Controls.Add(vr); } break; case "form:image": if (nodeChild.ParentNode==form.Node) { ODFImage img = new ODFImage(form, nodeChild); img.FixPropertyCollection(); form.Controls.Add(img); } break; case "form:image-frame": if (nodeChild.ParentNode==form.Node) { ODFImageFrame imgf = new ODFImageFrame(form, nodeChild); imgf.FixPropertyCollection(); form.Controls.Add(imgf); } break; case "form:grid": if (nodeChild.ParentNode==form.Node) { ODFGrid gr = new ODFGrid(form, nodeChild); gr.FixPropertyCollection(); gr.FixColumnCollection(); form.Controls.Add(gr); } break; default: if (nodeChild.ParentNode==form.Node) { ODFGenericControl gc = new ODFGenericControl(form, nodeChild); gc.FixPropertyCollection(); form.Controls.Add(gc); } break; } } form.RestoreControlEvents(); form.FixPropertyCollection(); // formnode.RemoveAll(); // formnode.InnerText = ""; } } catch(Exception ex) { throw new AODLException("Exception while processing a form:form node.", ex); } return form; }
public void ODFCheckBoxTest() { // Create a new document TextDocument document = new TextDocument(); document.New(); // Create a main paragraph Paragraph p =new Paragraph(document); // Create a main form ODFForm main_form = new ODFForm(document, "mainform"); main_form.Method = Method.Get; ODFCheckBox cb = new ODFCheckBox(main_form, p.Content, "cb1", "0cm", "0mm", "4cm", "5mm"); cb.Label = "Checkbox 1 (flat)"; cb.VisualEffect = VisualEffect.Flat; cb.IsTristate = XmlBoolean.True; cb.Value = "some_value"; cb.Title = "The first checkbox"; main_form.Controls.Add(cb); cb = new ODFCheckBox(main_form, p.Content, "cb2", "0cm", "5mm", "4cm", "5mm"); cb.Label = "Checkbox 2 (3d)"; cb.VisualEffect = VisualEffect.ThreeD; cb.IsTristate = XmlBoolean.False; cb.Value = "some_value_number_two"; cb.Title = "The second checkbox"; cb.CurrentState = State.Checked; main_form.Controls.Add(cb); cb = new ODFCheckBox(main_form, p.Content, "cb3", "0cm", "10mm", "4cm", "5mm"); cb.Label = "Checkbox 3 (grayed)"; cb.VisualEffect = VisualEffect.Flat; cb.IsTristate = XmlBoolean.True; cb.Value = "some_value_three"; cb.Title = "The third checkbox"; cb.CurrentState = State.Unknown; main_form.Controls.Add(cb); document.Forms.Add(main_form); document.Content.Add(p); // Button import/export test document.SaveTo(AARunMeFirstAndOnce.outPutFolder+"checkbox_test.odt"); document.Load(AARunMeFirstAndOnce.outPutFolder+"checkbox_test.odt"); document.SaveTo(AARunMeFirstAndOnce.outPutFolder+"checkbox_test2.odt"); }
public void HTMLExportTest() { //Create a new text document TextDocument document = new TextDocument(); document.New(); Paragraph p =new Paragraph(document); ODFForm main_form = new ODFForm(document, "mainform"); main_form.Method = Method.Get; main_form.Href="http://hello.foo.com"; ODFComboBox ccb = new ODFComboBox(main_form, p.Content, "ccb", "0mm", "0mm", "3cm", "1cm"); ccb.Size = 5; ccb.DropDown = XmlBoolean.True; ccb.Items.Add(new ODFItem(document, "Charlie")); ccb.Items.Add(new ODFItem(document, "John")); ccb.Items.Add(new ODFItem(document, "Dieter")); ccb.Items.Add(new ODFItem(document, "Bill")); ccb.Items.Add(new ODFItem(document, "Oleg")); ccb.Items.Add(new ODFItem(document, "Lars")); main_form.Controls.Add (ccb); ODFButton butt = new ODFButton(main_form, p.Content, "butt", "5mm", "15mm", "4cm", "1cm"); butt.Label = "A simple button :)"; main_form.Controls.Add (butt); ODFCheckBox cb = new ODFCheckBox(main_form, p.Content, "cbx", "5mm", "25mm", "4cm", "5mm"); cb.Label = "check it!"; cb.Name = "cbx"; cb.Value = "cbx_value"; main_form.Controls.Add (cb); document.Forms.Add(main_form); document.Content.Add(p); Paragraph text_p = new Paragraph(document); text_p.TextContent.Add(new SimpleText(document, "This is a simple text content that is located in the next paragraph after the form!")); document.Content.Add(text_p); document.SaveTo(AARunMeFirstAndOnce.outPutFolder+"html_test.odt"); document.SaveTo(AARunMeFirstAndOnce.outPutFolder+"html_test.html"); }
private void menuItem4_Click(object sender, System.EventArgs e) { if (saveFileDialog1.ShowDialog() == DialogResult.OK) { textDocument.New(); Paragraph p1 = new Paragraph(textDocument); p1.TextContent.Add(new SimpleText(textDocument, "This is a test form generated by the ODF Forms demo generator using the AODL library.")); Paragraph p2 = new Paragraph(textDocument); ODFForm fMain = textDocument.AddNewForm("mainform"); ODFFrame frame = new ODFFrame(fMain, p2.Content, "frame", "5mm", "5mm", "9cm", "5cm"); frame.Label = "Demo Form"; frame.AnchorType = AnchorType.Paragraph; ODFFixedText ft_name = new ODFFixedText(fMain, p2.Content, "ft_name", "8mm", "10mm", "3cm", "4mm"); ft_name.Label = "Name"; ODFTextArea name = new ODFTextArea(fMain, p2.Content, "name", "8mm", "14mm", "3cm", "5mm"); name.CurrentValue = eName.Text; name.AnchorType = AnchorType.Paragraph; ODFFixedText ft_surname = new ODFFixedText(fMain, p2.Content, "ft_surname", "8mm", "20mm", "3cm", "4mm"); ft_surname.Label = "Surname"; ODFTextArea surname = new ODFTextArea(fMain, p2.Content, "surname", "8mm", "24mm", "3cm", "5mm"); surname.CurrentValue = eSurname.Text; surname.AnchorType = AnchorType.Paragraph; ODFFixedText ft_gender = new ODFFixedText(fMain, p2.Content, "ft_gender", "8mm", "30mm", "3cm", "4mm"); ft_gender.Label = "Gender"; ODFListBox gender = new ODFListBox(fMain, p2.Content, "gender", "8mm", "35mm", "3cm", "5mm"); ODFOption male = new ODFOption(textDocument, "Male"); if (eGender.SelectedIndex == 0) male.CurrentSelected = XmlBoolean.True; gender.Options.Add(male); ODFOption female = new ODFOption(textDocument, "Female"); if (eGender.SelectedIndex == 1) female.CurrentSelected = XmlBoolean.True; gender.Options.Add(female); gender.AnchorType = AnchorType.Paragraph; gender.DropDown = XmlBoolean.True; ODFFixedText ft_age = new ODFFixedText(fMain, p2.Content, "ft_age", "8mm", "40mm", "3cm", "4mm"); ft_age.Label = "Age"; ODFFormattedText age = new ODFFormattedText(fMain, p2.Content, "age", "8mm", "44mm", "3cm", "5mm"); age.CurrentValue = eAge.Value.ToString(); age.MinValue = 16; age.MaxValue = 100; ODFFixedText ft_addinfo= new ODFFixedText(fMain, p2.Content, "ft_addinfo", "45mm", "10mm", "45mm", "4mm"); ft_addinfo.Label = "Additional information"; ODFTextArea addinfo = new ODFTextArea(fMain, p2.Content, "addinfo", "45mm", "14mm", "45mm", "25mm"); addinfo.CurrentValue = eAdditional.Text; addinfo.AnchorType = AnchorType.Paragraph; addinfo.Properties.Add(new SingleFormProperty(textDocument, PropertyValueType.Boolean, "MultiLine", "true")); ODFCheckBox usesaodl = new ODFCheckBox(fMain, p2.Content, "usesaodl", "45mm", "40mm", "45mm", "25mm"); if (eUsesAODL.Checked) usesaodl.CurrentState = State.Checked; usesaodl.Label = "This person uses AODL:)"; usesaodl.AnchorType = AnchorType.Paragraph; fMain.Controls.Add(frame); fMain.Controls.Add(ft_name); fMain.Controls.Add(name); fMain.Controls.Add(ft_surname); fMain.Controls.Add(surname); fMain.Controls.Add(ft_gender); fMain.Controls.Add(gender); fMain.Controls.Add(ft_age); fMain.Controls.Add(age); fMain.Controls.Add(ft_addinfo); fMain.Controls.Add(addinfo); fMain.Controls.Add(usesaodl); textDocument.Content.Add(p1); textDocument.Content.Add(p2); textDocument.SaveTo(saveFileDialog1.FileName); lastOpenedFile = saveFileDialog1.FileName; } }