<?xml version="1.0" encoding="UTF-8"?>
<!--
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 * This file incorporates work covered by the following license notice:
 *
 *   Licensed to the Apache Software Foundation (ASF) under one or more
 *   contributor license agreements. See the NOTICE file distributed
 *   with this work for additional information regarding copyright
 *   ownership. The ASF licenses this file to you under the Apache
 *   License, Version 2.0 (the "License"); you may not use this file
 *   except in compliance with the License. You may obtain a copy of
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
 -->
<helpdocument version="1.0">
  <meta>
    <topic id="textsbasicguidesample_codexml" indexer="include" status="PUBLISH">
      <title id="tit" xml-lang="en-US">Programming Examples for Controls in the Dialog Editor</title>
      <filename>/text/sbasic/guide/sample_code.xhp</filename>
    </topic>
    <history>
      <created date="2003-10-31T00:00:00">Sun Microsystems, Inc.</created>
    </history>
  </meta>
<body>
  <bookmark xml-lang="en-US" branch="index" id="bm_id3155338"><bookmark_value>programming examples for controls</bookmark_value>
  <bookmark_value>dialogs;loading (example)</bookmark_value>
  <bookmark_value>dialogs;displaying (example)</bookmark_value>
  <bookmark_value>controls;reading or editing properties (example)</bookmark_value>
  <bookmark_value>list boxes;removing entries from (example)</bookmark_value>
  <bookmark_value>list boxes;adding entries to (example)</bookmark_value>
  <bookmark_value>examples; programming controls</bookmark_value>
  <bookmark_value>dialog editor;programming examples for controls</bookmark_value>
  <bookmark_value>Tools;LoadDialog</bookmark_value>
</bookmark>
<section id="samplecode">
   <paragraph role="heading" id="hd_id3155338" xml-lang="en-US" level="1"><variable id="sample_code"><link href="text/sbasic/guide/sample_code.xhp">Programming Examples for Controls in the Dialog Editor</link>
   </variable></paragraph>
</section>
<paragraph role="paragraph" id="par_id3153031" xml-lang="en-US">The following examples are for a new <link href="text/sbasic/guide/create_dialog.xhp">dialog</link> called "Dialog1". Use the tools on the <emph>Toolbox</emph> bar in the dialog editor to create the dialog and add the following controls: a <emph>Check Box</emph> called "CheckBox1", a <emph>Label Field</emph> called "Label1", a <emph>Button</emph> called "CommandButton1", and a <emph>List Box</emph> called "ListBox1".</paragraph>
<paragraph role="warning" id="par_id3154141" xml-lang="en-US">Be consistent with uppercase and lowercase letter when you attach a control to an object variable.</paragraph>
<h3 id="hd_id3154909">Global Function for Loading Dialogs</h3>
<bascode>
<paragraph role="bascode" id="par_id3153193" xml-lang="en-US" localize="false">Function LoadDialog(Libname as String, DialogName as String, Optional oLibContainer)</paragraph>
<paragraph role="bascode" id="par_id3145787" xml-lang="en-US" localize="false">Dim oLib as Object ' com.sun.star.script.XLibraryContainer</paragraph>
<paragraph role="bascode" id="par_id3148576" xml-lang="en-US" localize="false">Dim oLibDialog as Object</paragraph>
<paragraph role="bascode" id="par_id3153726" xml-lang="en-US" localize="false">Dim oRuntimeDialog as Object</paragraph>
<paragraph role="bascode" id="par_id3149261" xml-lang="en-US" localize="false">    If IsMissing(oLibContainer) Then</paragraph>
<paragraph role="bascode" id="par_id3148646" xml-lang="en-US" localize="false">        oLibContainer = DialogLibraries</paragraph>
<paragraph role="bascode" id="par_id3151115" xml-lang="en-US" localize="false">    End If</paragraph>
<paragraph role="bascode" id="par_id3146986" xml-lang="en-US" localize="false">    oLibContainer.LoadLibrary(LibName)</paragraph>
<paragraph role="bascode" id="par_id3145366" xml-lang="en-US" localize="false">    oLib = oLibContainer.GetByName(Libname)</paragraph>
<paragraph role="bascode" id="par_id3145271" xml-lang="en-US" localize="false">    oLibDialog = oLib.GetByName(DialogName)</paragraph>
<paragraph role="bascode" id="par_id3144764" xml-lang="en-US" localize="false">    oRuntimeDialog = CreateUnoDialog(oLibDialog)</paragraph>
<paragraph role="bascode" id="par_id3153876" xml-lang="en-US" localize="false">    LoadDialog() = oRuntimeDialog</paragraph>
<paragraph role="bascode" id="par_id3156286" xml-lang="en-US" localize="false">End Function</paragraph>
</bascode>
<paragraph role="paragraph" id="par_id3153032" xml-lang="en-US"><literal>LoadDialog</literal> function is stored in <literal>Tools.ModuleControls</literal> available from Application Macros and Dialogs.</paragraph>
<h3 id="hd_id3149412">Displaying a Dialog</h3>
<bascode>
<paragraph role="bascode" id="par_id3145801" xml-lang="en-US">REM global definition of variables</paragraph>
<paragraph role="bascode" id="par_id3150716" xml-lang="en-US" localize="false">Dim oDialog1 AS Object</paragraph>
<paragraph role="bascode" id="par_id3154510" xml-lang="en-US" localize="false">Sub StartDialog1</paragraph>
<paragraph role="bascode" id="par_id6715587" xml-lang="en-US" localize="false">    With GlobalScope.BasicLibraries</paragraph>
<paragraph role="bascode" id="par_id3148575" xml-lang="en-US" localize="false">       If Not .IsLibraryLoaded("Tools") Then .LoadLibrary("Tools")</paragraph>
<paragraph role="bascode" id="par_id5815587" xml-lang="en-US" localize="false">    End With</paragraph>
<paragraph role="bascode" id="par_id3150327" xml-lang="en-US" localize="false">    oDialog1 = Tools.ModuleControls.LoadDialog("Standard", "Dialog1")</paragraph>
<paragraph role="bascode" id="par_id3155767" xml-lang="en-US" localize="false">    oDialog1.Execute()</paragraph>
<paragraph role="bascode" id="par_id3149019" xml-lang="en-US" localize="false">End Sub</paragraph>
</bascode>
<h3 id="hd_id3150042">Read or Edit Properties of Controls in the Program</h3>
<bascode>
<paragraph role="bascode" id="par_id3159267" xml-lang="en-US" localize="false">Sub Sample1</paragraph>
<paragraph role="bascode" id="par_id6715588" xml-lang="en-US" localize="false">    With GlobalScope.Basiclibraries</paragraph>
<paragraph role="bascode" id="par_id1148578" xml-lang="en-US" localize="false">       If Not .IsLibraryLoaded("Tools") Then .LoadLibrary("Tools")</paragraph>
<paragraph role="bascode" id="par_id5815588" xml-lang="en-US" localize="false">    End With</paragraph>
<paragraph role="bascode" id="par_id3163808" xml-lang="en-US" localize="false">    oDialog1 = Tools.LoadDialog("Standard", "Dialog1")</paragraph>
<paragraph role="bascode" id="par_id3145232" xml-lang="en-US">    REM get dialog model</paragraph>
<paragraph role="bascode" id="par_id3146316" xml-lang="en-US" localize="false">    oDialog1Model = oDialog1.Model</paragraph>
<paragraph role="bascode" id="par_id3154021" xml-lang="en-US">    REM display text of Label1</paragraph>
<paragraph role="bascode" id="par_id3150301" xml-lang="en-US" localize="false">    oLabel1 = oDialog1.GetControl("Label1")</paragraph>
<paragraph role="bascode" id="par_id3152584" xml-lang="en-US" localize="false">    MsgBox oLabel1.Text</paragraph>
<paragraph role="bascode" id="par_id3151277" xml-lang="en-US">    REM set new text for control Label1</paragraph>
<paragraph role="bascode" id="par_id3154119" xml-lang="en-US">    oLabel1.Text = "New Files"</paragraph>
<paragraph role="bascode" id="par_id3155115" xml-lang="en-US">    REM display model properties for the control CheckBox1</paragraph>
<paragraph role="bascode" id="par_id3166426" xml-lang="en-US" localize="false">    oCheckBox1Model = oDialog1Model.CheckBox1</paragraph>
<paragraph role="bascode" id="par_id3153270" xml-lang="en-US" localize="false">    MsgBox oCheckBox1Model.Dbg_Properties</paragraph>
<paragraph role="bascode" id="par_id3149817" xml-lang="en-US">    REM set new state for CheckBox1 for model of control</paragraph>
<paragraph role="bascode" id="par_id3145134" xml-lang="en-US" localize="false">    oCheckBox1Model.State = 1</paragraph>
<paragraph role="bascode" id="par_id3159102" xml-lang="en-US">    REM display model properties for control CommandButton1</paragraph>
<paragraph role="bascode" id="par_id3152777" xml-lang="en-US" localize="false">    oCMD1Model = oDialog1Model.CommandButton1</paragraph>
<paragraph role="bascode" id="par_id3149209" xml-lang="en-US" localize="false">    MsgBox oCMD1Model.Dbg_Properties</paragraph>
<paragraph role="bascode" id="par_id3150368" xml-lang="en-US">    REM display properties of control CommandButton1</paragraph>
<paragraph role="bascode" id="par_id3150883" xml-lang="en-US" localize="false">    oCMD1 = oDialog1.GetControl("CommandButton1")</paragraph>
<paragraph role="bascode" id="par_id3155380" xml-lang="en-US" localize="false">    MsgBox oCMD1.Dbg_Properties</paragraph>
<paragraph role="bascode" id="par_id3150201" xml-lang="en-US">    REM execute dialog</paragraph>
<paragraph role="bascode" id="par_id3154485" xml-lang="en-US" localize="false">    oDialog1.Execute()</paragraph>
<paragraph role="bascode" id="par_id3146115" xml-lang="en-US" localize="false">End Sub</paragraph>
</bascode>
<h3 id="hd_id3145387">Add an Entry to a ListBox</h3>
<bascode>
<paragraph role="bascode" id="par_id3155088" xml-lang="en-US" localize="false">Sub AddEntry</paragraph>
<paragraph role="bascode" id="par_id6715589" xml-lang="en-US" localize="false">    With GlobalScope.Basiclibraries</paragraph>
<paragraph role="bascode" id="par_id3148577" xml-lang="en-US" localize="false">       If Not .IsLibraryLoaded("Tools") Then .LoadLibrary("Tools")</paragraph>
<paragraph role="bascode" id="par_id5815589" xml-lang="en-US" localize="false">    End With</paragraph>
<paragraph role="bascode" id="par_id3159222" xml-lang="en-US" localize="false">    oDialog1 = ModuleControls.LoadDialog("Standard", "Dialog1")</paragraph>
<paragraph role="bascode" id="par_id3148700" xml-lang="en-US">    REM adds a new entry to the ListBox</paragraph>
<paragraph role="bascode" id="par_id3159173" xml-lang="en-US" localize="false">    oDialog1Model = oDialog1.Model</paragraph>
<paragraph role="bascode" id="par_id3153305" xml-lang="en-US" localize="false">    oListBox = oDialog1.GetControl("ListBox1")</paragraph>
<paragraph role="bascode" id="par_id3153914" xml-lang="en-US" localize="false">    Dim iCount as integer</paragraph>
<paragraph role="bascode" id="par_id3151243" xml-lang="en-US" localize="false">    iCount = oListbox.ItemCount</paragraph>
<paragraph role="bascode" id="par_id3144504" xml-lang="en-US">    oListbox.additem("New Item" &amp; iCount,0)</paragraph>
<paragraph role="bascode" id="par_id3149328" xml-lang="en-US" localize="false">End Sub</paragraph>
</bascode>
<h3 id="hd_id3147071">Remove an Entry from a ListBox</h3>
<bascode>
<paragraph role="bascode" id="par_id3159095" xml-lang="en-US" localize="false">Sub RemoveEntry</paragraph>
<paragraph role="bascode" id="par_id6715590" xml-lang="en-US" localize="false">    With GlobalScope.Basiclibraries</paragraph>
<paragraph role="bascode" id="par_id3148578" xml-lang="en-US" localize="false">       If Not .IsLibraryLoaded("Tools") Then .LoadLibrary("Tools")</paragraph>
<paragraph role="bascode" id="par_id5815590" xml-lang="en-US" localize="false">    End With</paragraph>
<paragraph role="bascode" id="par_id3149443" xml-lang="en-US" localize="false">    oDialog1 = Tools.ModuleControls.LoadDialogLoadDialog("Standard", "Dialog1")</paragraph>
<paragraph role="bascode" id="par_id3153247" xml-lang="en-US">    REM remove the first entry from the ListBox</paragraph>
<paragraph role="bascode" id="par_id3151302" xml-lang="en-US" localize="false">    oDialog1Model = oDialog1.Model</paragraph>
<paragraph role="bascode" id="par_id3153976" xml-lang="en-US" localize="false">    oListBox = oDialog1.GetControl("ListBox1")</paragraph>
<paragraph role="bascode" id="par_id3155383" xml-lang="en-US" localize="false">    oListbox.removeitems(0,1)</paragraph>
<paragraph role="bascode" id="par_id3150892" xml-lang="en-US" localize="false">End Sub</paragraph>
</bascode>
<section id="relatedtopics">
<embed href="text/sbasic/guide/control_properties.xhp#control_properties"/>
<embed href="text/sbasic/guide/create_dialog.xhp#create_dialog"/>
<embed href="text/sbasic/guide/insert_control.xhp#insert_control"/>
<embed href="text/sbasic/guide/show_dialog.xhp#show_dialog"/>
</section>
</body>
</helpdocument>
