Commits

Jason McKesson committed 625beba

LuaGUI: Edit boxes can get per-keystroke changes. Dropdowns can also be editable.

  • Participants
  • Parent commits 41b3afd

Comments (0)

Files changed (3)

File Docs/LuaGUI.xml

                             <para>Optional.</para>
                         </glossdef>
                     </glossentry>
+                    <glossentry>
+                        <glossterm>onchange</glossterm>
+                        <glossdef>
+                            <para>A Lua chunk that will be called when the user changes the text in
+                                any way. It is given the text in the box as the first parameter, and
+                                the event as the second.</para>
+                            <para>Optional.</para>
+                        </glossdef>
+                    </glossentry>
                 </glosslist>
             </section>
             <section>
                 <glosslist>
                     <title>Dropdown Box Attributes</title>
                     <glossentry>
+                        <glossterm>edit</glossterm>
+                        <glossdef>
+                            <para>Tells whether the user can enter strings in the dropdown or not.
+                                If it is <literal>true</literal>, then the user can enter strings.
+                                If it is <literal>false</literal>, then the user cannot.</para>
+                            <para>Optiona. Defaults to <literal>false</literal>.</para>
+                        </glossdef>
+                    </glossentry>
+                    <glossentry>
                         <glossterm>sort</glossterm>
                         <glossdef>
                             <para>This tells whether the dropdown box is sorted by string or not. If
                             <para>Optional.</para>
                         </glossdef>
                     </glossentry>
+                    <glossentry>
+                        <glossterm>onentry</glossterm>
+                        <glossdef>
+                            <para>A Lua chunk that will be called when the user presses the enter
+                                key while in a list box. It is given the text in the box as the
+                                first parameter, and the event as the second.</para>
+                            <para>Optional.</para>
+                        </glossdef>
+                    </glossentry>
                 </glosslist>
             </section>
             <section>

File Docs/luagui.rnc

         lg.editbox.multiline.attribute?,
         lg.editbox.readonly.attribute?,
         lg.editbox.default.attribute?,
-        lg.editbox.onentry.attribute?
+        lg.editbox.onentry.attribute?,
+        lg.editbox.onchange.attribute?
     
     lg.spinner.attlist =
         lg.std.window.attlist,
         lg.size,
         lg.positioning.attlist,
         lg.label.attlist,
+        lg.dropdown.edit.attribute?,
         lg.dropdown.sort.attribute?,
         lg.dropdown.oncreate.attribute?,
-        lg.dropdown.onselchange.attribute?
+        lg.dropdown.onselchange.attribute?,
+        lg.dropdown.onentry.attribute?
     
     lg.positioning.attlist =
         (lg.positioning.align.attribute | lg.positioning.halign.attribute)?,
         ## The label for this control. It will be vertically above the control.
         attribute vlabel { text }
 
+    lg.dropdown.edit.attribute =
+        ## Set to true if you want the ability to change the text in an dropdown.
+        [ a:defaultValue = "false" ]
+        attribute edit { lg.data.boolean }
+
     lg.dropdown.sort.attribute =
         ## Set to true if you want the entries in the dropdown box to be sorted.
         [ a:defaultValue = "false" ]
         ## A Lua function that is called whenever an item in the dropdown is selected.
         ## The function is given the event as a parameter.
         attribute onselchange { lg.luafunction }
+        
+    lg.dropdown.onentry.attribute =
+        ## A Lua function that is called when the text is changed by the user and enter is pressed.
+        ## The function is given the event as a parameter.
+        attribute onentry { lg.luafunction }
 
     lg.listbox.type.attribute =
         ## The kind of listbox. There are three possibilities.
         ## box. The first parameter is the string the user entered in the box, and the second
         ## parameter is the event object.
         attribute onentry { lg.luafunction }
+    
+    lg.editbox.onchange.attribute =
+        ## A Lua chunk that will be called when the user changes the text in any way. It is
+        ## given the text in the box as the first parameter, and the event as the second.
+        attribute onchange { lg.luafunction }
 
     lg.radio.name.attribute =
         ## The name of the radio button. Each radio button should have a unique name.

File Tools/LuaGUI.lua

 	return info;
 end
 
-local function RegisterEventHandlers(currNode, wnd, eventList)
+local function RegisterEventHandlers(currNode, wnd, eventList, ConvertFunc)
 	for i=1,#eventList do
 		local currEvt = eventList[i];
 		local bHasProp, prop = currNode:GetPropVal(currEvt.name);
 
 			wnd:Connect(currEvt.event,
 				function(event)
-					func(event);
+					if(ConvertFunc) then
+						func(ConvertFunc(event));
+					else
+						func(event);
+					end
 					event:Skip();
 				end);
 		end
 	return radio;
 end
 
+local editboxEventTable =
+{
+	{name="onentry", event=wx.wxEVT_COMMAND_TEXT_ENTER},
+	{name="onchange", event=wx.wxEVT_COMMAND_TEXT_UPDATED},
+}
+
 function elementJumpTable.editbox(parWnd, sizer, currNode, notebook, auiNotebook)
 	local size = GetNodeSize(currNode);
 	local style = wx.wxTE_NOHIDESEL;
 	FinalizeControl(currNode, editbox);
 	AddToSizerWithLabel(parWnd, currNode, editbox, sizer);
 	
-	if(bHasEntry) then
-		local func = loadstring(strEntry);
-		editbox:Connect(wx.wxEVT_COMMAND_TEXT_ENTER,
-			function(cmdEvent)
-				func(cmdEvent:GetString(), cmdEvent);
-				cmdEvent:Skip();
-			end);
-	end
+	RegisterEventHandlers(currNode, editbox, editboxEventTable,
+		function(event)
+			return event:GetString(), event;
+		end);
 
 	return editbox;
 end
 end
 
 local dropdownEventTable = {
-{name="onselchange", event=wx.wxEVT_COMMAND_COMBOBOX_SELECTED},
+	{name="onselchange", event=wx.wxEVT_COMMAND_COMBOBOX_SELECTED},
+	{name="onentry", event=wx.wxEVT_COMMAND_TEXT_ENTER}
 };
 
 function elementJumpTable.dropdown(parWnd, sizer, currNode, notebook, auiNotebook)
 	local size = GetNodeSize(currNode);
-	local style = wx.wxCB_DROPDOWN + wx.wxCB_READONLY;
+	local style = wx.wxCB_DROPDOWN;
 	
+	if(not GetNodeBoolProp(currNode, "edit", false)) then style = style + wx.wxCB_READONLY; end
 	if(GetNodeBoolProp(currNode, "sort", false)) then style = style + wx.wxCB_SORT; end
 	
 	local dropdown = wx.wxComboBox(parWnd, wx.wxID_ANY, "", wx.wxDefaultPosition, size, 
 	return dropdown;
 end
 
+--[==[
+function elementJumpTable.listctrl(parWnd, sizer, currNode, notebook, auiNotebook)
+	local size = GetNodeSize(currNode);
+
+	local list = wx.wxListCtrl(parWnd, wx.wxID_ANY, wx.wxDefaultPosition, size,
+	wx.wxLC_REPORT + wx.wxLC_EDIT_LABELS + wx.wxLC_HRULES + wx.wxLC_VRULES);
+
+	list:InsertColumn(0, "Name");
+	list:InsertColumn(1, "Gran");
+	list:InsertItem(0, "foo");
+	list:SetItem(0, 1, "Something more than that.");
+	list:InsertItem(1, "bar");
+	list:InsertItem(2, "fia");
+	list:InsertItem(3, "lsia");
+
+	list:Connect(wx.wxEVT_COMMAND_LIST_COL_CLICK,
+		function(event)
+			print(event:GetText(), event:GetColumn());
+			event:Skip();
+		end);
+		
+	
+
+	FinalizeControl(currNode, list);
+	AddToSizer(currNode, list, sizer);
+
+	return list;
+end
+]==]
+
+
 --[[
 local uncheckedBox =
 {