Advertisement
ZeroAccend

AHK GUI Creator

Jan 23rd, 2017
1,118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 45.64 KB | None | 0 0
  1. #SingleInstance,Force
  2. ;Menu, Tray, Icon, % A_ScriptDir "\GuiIcon.ico"
  3. global settings,window,conxml,TreeView,v:=[]
  4. settings:=new xml("settings","lib\Settings.xml"),TreeView:=new xml("TreeView")
  5. filecheck(),Gui()
  6. /*
  7. re-explore the WheelDown/WheelUp to change edit modes
  8. give it a StatusBar to display the mode or window title
  9. escape de=selects all
  10. change{
  11. first item to:{
  12. for anything that is just Text
  13. Control Text:
  14. for anything that needs a list
  15. Control List:
  16. for Tab
  17. Control Tabs:
  18. and so on
  19. }
  20. }
  21. info window{
  22. have the add items display the hotkeys
  23. }
  24. Tab Logic{
  25. when you make a tab control
  26. <control type="tab">
  27. <tab tab="1">
  28. if you add tabs
  29. add the <tab tab="A_Index"> per tab|dec|la|ra|tion
  30.  
  31. if change tabs and and dec|la|ra is less than <tab>.length{
  32. WARN! and ask what to do with the orphaned tab items
  33. if delete
  34. delete the controls
  35. else
  36. Ask where to move the tabs
  37. }
  38. }
  39. */
  40. FileCheck(){
  41. if !FileExist("lib")
  42. FileCreateDir,lib
  43. conxml:=new xml("controls","lib\controls.xml")
  44. if (conxml.ssn("//version").text!="0.000.2")
  45. FileDelete,lib\controls.xml
  46. if !FileExist("lib\controls.xml")
  47. ctrl:=URLDownloadToVar("http://files.maestrith.com/GUI_Creator/Controls.xml"),conxml:=new xml("control","lib\Controls.xml"),conxml.xml.loadxml(ctrl),conxml.save(1)
  48. if !FileExist("tile.bmp")
  49. MakeBackground()
  50. }
  51. URLDownloadToVar(url){
  52. http:=ComObjCreate("WinHttp.WinHttpRequest.5.1")
  53. http.Open("GET",url),http.Send()
  54. return http.ResponseText
  55. }
  56. class xml{
  57. keep:=[]
  58. __New(param*){
  59. if !FileExist(A_ScriptDir "\lib")
  60. FileCreateDir,%A_ScriptDir%\lib
  61. root:=param.1,file:=param.2
  62. file:=file?file:root ".xml"
  63. temp:=ComObjCreate("MSXML2.DOMDocument"),temp.setProperty("SelectionLanguage","XPath")
  64. this.xml:=temp
  65. ifexist %file%
  66. temp.load(file),this.xml:=temp
  67. else
  68. this.xml:=this.CreateElement(temp,root)
  69. this.file:=file
  70. xml.keep[root]:=this
  71. }
  72. CreateElement(doc,root){
  73. return doc.AppendChild(this.xml.CreateElement(root)).parentnode
  74. }
  75. search(node,find,return=""){
  76. found:=this.xml.SelectNodes(node "[contains(.,'" RegExReplace(find,"&","')][contains(.,'") "')]")
  77. while,ff:=found.item(a_index-1)
  78. if (ff.text=find){
  79. if return
  80. return ff.SelectSingleNode("../" return)
  81. return ff.SelectSingleNode("..")
  82. }
  83. }
  84. lang(info){
  85. info:=info=""?"XPath":"XSLPattern"
  86. this.xml.temp.setProperty("SelectionLanguage",info)
  87. }
  88. unique(info){
  89. if (info.check&&info.text)
  90. return
  91. if info.under{
  92. if info.check
  93. find:=info.under.SelectSingleNode("*[@" info.check "='" info.att[info.check] "']")
  94. if info.Text
  95. find:=this.cssn(info.under,"*[text()='" info.text "']")
  96. if !find
  97. find:=this.under({under:info.under,att:info.att,node:info.path})
  98. for a,b in info.att
  99. find.SetAttribute(a,b)
  100. }
  101. else
  102. {
  103. if info.check
  104. find:=this.ssn("//" info.path "[@" info.check "='" info.att[info.check] "']")
  105. else if info.text
  106. find:=this.ssn("//" info.path "[text()='" info.text "']")
  107. if !find
  108. find:=this.add({path:info.path,att:info.att,dup:1})
  109. for a,b in info.att
  110. find.SetAttribute(a,b)
  111. }
  112. if info.text
  113. find.text:=info.text
  114. return find
  115. }
  116. add(info){
  117. path:=info.path,p:="/",dup:=this.ssn("//" path)?1:0
  118. if next:=this.ssn("//" path)?this.ssn("//" path):this.ssn("//*")
  119. Loop,Parse,path,/
  120. last:=A_LoopField,p.="/" last,next:=this.ssn(p)?this.ssn(p):next.appendchild(this.xml.CreateElement(last))
  121. if (info.dup&&dup)
  122. next:=next.parentnode.appendchild(this.xml.CreateElement(last))
  123. for a,b in info.att
  124. next.SetAttribute(a,b)
  125. if info.text!=""
  126. next.text:=info.text
  127. return next
  128. }
  129. find(info){
  130. if info.att.1&&info.text
  131. return m("You can only search by either the attribut or the text, not both")
  132. search:=info.path?"//" info.path:"//*"
  133. for a,b in info.att
  134. search.="[@" a "='" b "']"
  135. if info.text
  136. search.="[text()='" info.text "']"
  137. current:=this.ssn(search)
  138. return current
  139. }
  140. under(info){
  141. new:=info.under.appendchild(this.xml.createelement(info.node))
  142. for a,b in info.att
  143. new.SetAttribute(a,b)
  144. new.text:=info.text
  145. return new
  146. }
  147. ssn(node){
  148. return this.xml.SelectSingleNode(node)
  149. }
  150. sn(node){
  151. return this.xml.SelectNodes(node)
  152. }
  153. __Get(x=""){
  154. return this.xml.xml
  155. }
  156. Get(path,Default){
  157. return value:=this.ssn(path).text!=""?this.ssn(path).text:Default
  158. }
  159. transform(){
  160. static
  161. if !IsObject(xsl){
  162. xsl:=ComObjCreate("MSXML2.DOMDocument")
  163. style=
  164. (
  165. <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  166. <xsl:output method="xml" indent="yes" encoding="UTF-8"/>
  167. <xsl:template match="@*|node()">
  168. <xsl:copy>
  169. <xsl:apply-templates select="@*|node()"/>
  170. <xsl:for-each select="@*">
  171. <xsl:text></xsl:text>
  172. </xsl:for-each>
  173. </xsl:copy>
  174. </xsl:template>
  175. </xsl:stylesheet>
  176. )
  177. xsl.loadXML(style),style:=null
  178. }
  179. this.xml.transformNodeToObject(xsl,this.xml)
  180. }
  181. save(x*){
  182. if x.1=1
  183. this.Transform()
  184. filename:=this.file?this.file:x.1.1
  185. file:=fileopen(filename,3,"UTF-8"),file.seek(0),file.write(this[]),file.length(file.position)
  186. }
  187. remove(rem){
  188. if !IsObject(rem)
  189. rem:=this.ssn(rem)
  190. rem.ParentNode.RemoveChild(rem)
  191. }
  192. ea(path){
  193. list:=[]
  194. if nodes:=path.nodename
  195. nodes:=path.SelectNodes("@*")
  196. else if path.text
  197. nodes:=this.sn("//*[text()='" path.text "']/@*")
  198. else if !IsObject(path)
  199. nodes:=this.sn(path "/@*")
  200. else
  201. for a,b in path
  202. nodes:=this.sn("//*[@" a "='" b "']/@*")
  203. while,n:=nodes.item(A_Index-1)
  204. list[n.nodename]:=n.text
  205. return list
  206. }
  207. }
  208. ssn(node,path){
  209. return node.selectsinglenode(path)
  210. }
  211. sn(node,path){
  212. return node.selectnodes(path)
  213. }
  214. m(x*){
  215. for a,b in x
  216. list.=b "`n"
  217. MsgBox,0,GUI Creator,%list%
  218. }
  219. t(x*){
  220. for a,b in x
  221. list.=b "`n"
  222. ToolTip %list%
  223. }
  224. Gui(){
  225. static
  226. Gui,+Resize +hwndmain
  227. hwnd(1,main),OnMessage(0x136,"Display_Grid"),OnMessage(0x231,"KillSelect"),OnMessage(0x232,"highlight")
  228. DetectHiddenWindows,On
  229. OnMessage(0x201,"LButton")
  230. Gui,1:Menu,% Menu()
  231. Gui,2:+parent1 +Resize +hwndhwnd -0x20000 -0x10000 0x400 -ToolWindow
  232. Gui,2:Add,TreeView,x0 y0 w150 h500 gtv AltSubmit hwndtv
  233. Gui,2:Default
  234. add:=TreeView.Add({path:"Add",att:{tv:TV_Add("Add Control")}}),ea:=TreeView.ea(add),hwnd("tv",tv)
  235. for a,b in StrSplit(Menu({menu:1}).Add,"|")
  236. TreeView.under({under:add,node:b,att:{tv:TV_Add(b,ea.tv,"Vis")}})
  237. TreeView.Add({path:"displaypos",att:{tv:TV_Add("Display Positions")}})
  238. TreeView.Add({path:"selected",att:{tv:TV_Add("Selected")}})
  239. TreeView.add({path:"windowtitle",att:{tv:TV_Add("Window Title")}})
  240. TreeView.add({path:"windowname",att:{tv:TV_Add("Window Name")}})
  241. hwnd(2,hwnd),ea:=settings.ea("//gui/settings")
  242. if (ea.w)
  243. ControlMove,SysTreeView321,,,% ea.w,% ea.h,% hwnd([2])
  244. Gui,2:Show,% guipos("//gui/settings","x5 y5 w150 h500"),Settings
  245. Gui,3:+Resize +hwndhwnd -0x20000 -0x10000 +parent1 -ToolWindow
  246. hwnd(3,hwnd),ea:=settings.ea("//gui/workarea"),pos:=""
  247. Gui,3:Show,% guipos("//gui/workarea","x176 y5 w500 h500"),Work Area
  248. Gui,3:Margin,0,0
  249. for a,b in {Border:33,Caption:4,Menu:15}{
  250. SysGet,value,%b%
  251. v[a]:=value
  252. }
  253. Gui,1:Show,% guipos("//gui/main","w700 h550"),GUI Creator
  254. Hotkey,IfWinActive,% hwnd([1])
  255. Hotkey,^a,SelectAll,On
  256. Hotkey,+^a,SelectAll,On
  257. Hotkey,^z,Undo,On
  258. Hotkey,^y,Redo,On
  259. Hotkey,~Escape,Escape,On
  260. Hotkey,Delete,Delete,On
  261. WinSet,Redraw,,% hwnd([3])
  262. hotkeys(),options(1),new()
  263. if last:=settings.ssn("//last/@file").text
  264. open(last),DisplaySelected()
  265. new Undo()
  266. return
  267. 2GuiSize:
  268. ControlMove,SysTreeView321,,,A_GuiWidth,A_GuiHeight,% hwnd([2])
  269. return
  270. 2GuiClose:
  271. 3GuiClose:
  272. exit(1)
  273. return
  274. }
  275. hwnd(win,hwnd=""){
  276. static winkeep:=[]
  277. if (win.rem){
  278. Gui,% win.rem ":Destroy"
  279. return winkeep.remove(win.rem)
  280. }
  281. if IsObject(win)
  282. return "ahk_id" winkeep[win.1]
  283. if !hwnd
  284. return winkeep[win]
  285. winkeep[win]:=hwnd
  286. return % "ahk_id" hwnd
  287. }
  288. Menu(info:=""){
  289. static menu:={order:["File","Edit","Options","Add","Help"],File:"&New|&Save|S&ave As|&Open|Ex&port|&Test GUI|E&xit|&Update Program",Add:"Button|Checkbox|ComboBox|DateTime|DropDownList|Edit|GroupBox|Hotkey|ListBox|ListView|MonthCal|Picture|Progress|Radio|Slider|Tab|Text|TreeView|UpDown",Options:"&Snap To Grid|Display &Grid|Grid &Dot Color|Grid &Background|Debug &Window",Edit:"Edit GLabels|Select All|Invert Selection|Edit &Hotkeys|Redraw",Help:"Help|Online Help"}
  290. if info.menu
  291. return menu
  292. for a,b in Menu.order{
  293. for c,d in StrSplit(Menu[b],"|"){
  294. HotkeyXML({check:d})
  295. Menu,%b%,Add,% GetMenuItem(d),menucmd
  296. }
  297. }
  298. for a,b in Menu.order
  299. Menu,Main,Add,&%b%,:%b%
  300. return "main"
  301. menucmd:
  302. MenuItem:=clean(A_ThisMenuItem)
  303. if(A_ThisMenu="options"&&MenuItem~="(Snap_To_Grid|Display_Grid|Debug_Window)")
  304. return options(MenuItem)
  305. if(A_ThisMenuItem="Debug Window")
  306. m("here")
  307. if(IsFunc(MenuItem))
  308. %MenuItem%()
  309. else if(A_ThisMenu="Add")
  310. GetInfo(MenuItem)
  311. else
  312. m("Feature not implemented yet. Coming Soon")
  313. return
  314. }
  315. HotkeyXML(item){
  316. if item.check
  317. if !settings.ssn("//hotkeys/*[@menu='" item.check "']")
  318. settings.Add({path:"hotkeys/" clean(item.check),att:{menu:item.check}})
  319. }
  320. Clean(info,type:=0){
  321. if InStr(info,"`t")
  322. info:=RegExReplace(info,"(\t.*)")
  323. if type=1
  324. info:=RegExReplace(info,"_"," ")
  325. else if(type=2)
  326. info:=RegExReplace(info,"&")
  327. else if(type=0)
  328. info:=RegExReplace(RegExReplace(info," ","_"),"&")
  329. return info
  330. }
  331. GuiPos(path,default){
  332. ea:=settings.ea(path)
  333. for a,b in ea
  334. if (b!="")
  335. pos.=a b " "
  336. return pos:=pos?pos:default
  337. }
  338. Open(filename=""){
  339. last:=settings.ssn("//last/@file").text,tabcount:=0
  340. SplitPath,last,,dir
  341. if !filename
  342. FileSelectFile,filename,,%dir%,Select a Saved GUI,*.xml
  343. if (ErrorLevel||!FileExist(filename))
  344. return
  345. New(),window.xml.load(filename),list:=window.sn("//*[@type]")
  346. while,ll:=list.Item[A_Index-1]
  347. ll.RemoveAttribute("hwnd")
  348. while,ll:=window.sn("//window/descendant::*").Item[A_Index-1],ea:=xml.ea(ll){
  349. if(InStr(ea.type,"tab"))
  350. tabcount++
  351. if(ll.nodename="tab"){
  352. Gui,3:Tab,% ea.tab,% SubStr(GetClassNN(ssn(ll,"ancestor::control[@type='Tab' or @type='Tab2']/@hwnd").text),16)
  353. ll.SetAttribute("hwnd",ssn(ll.ParentNode,"@hwnd").text)
  354. Continue
  355. }
  356. if !ssn(ll,"ancestor::control[@type='Tab' or @type='Tab2']")
  357. Gui,3:Tab
  358. AddControl(ll)
  359. }
  360. ea:=window.ea("//workarea")
  361. ControlMove,,% ea.x,% ea.y,% ea.w,% ea.h,% hwnd([3])
  362. settings.Add({path:"last",att:{file:filename}}),Highlight(),eval()
  363. Gui,3:Tab
  364. }
  365. GetMenuItem(menu,tv:=0){
  366. hotkey:=settings.ssn("//hotkeys/" clean(menu) "/@hotkey").text
  367. space:=tv?" = ":"`t",menu:=tv?RegExReplace(menu,"&"):menu
  368. hotkey:=hotkey?menu space Convert_Hotkey(hotkey):menu
  369. return hotkey
  370. }
  371. Options(x:=""){
  372. if (x=1){
  373. for a,b in StrSplit(menu({menu:1}).options,"|"){
  374. if settings.ssn("//options/" clean(b)).text
  375. Menu,options,Check,%b%
  376. else
  377. Menu,options,UnCheck,%b%
  378. }
  379. func:=clean(b)
  380. if IsFunc(func)
  381. %func%()
  382. WinSet,Redraw,,% hwnd([3])
  383. return
  384. }
  385. settings.Add({path:"options/" clean(x),text:settings.ssn("//options/" clean(x)).text?0:1}),options(1)
  386. if(clean(x)="debug_window")
  387. debug(0)
  388. }
  389. Dlg_Color(Color,hwnd:=""){
  390. static
  391. VarSetCapacity(cccc,16*A_PtrSize,0),cc:=1,size:=VarSetCapacity(CHOOSECOLOR,9*A_PtrSize,0)
  392. Loop,16
  393. NumPut(settings.ssn("//colors/@color" A_Index).text,cccc,(A_Index-1)*4,"UInt")
  394. NumPut(size,CHOOSECOLOR,0,"UInt"),NumPut(hwnd,CHOOSECOLOR,A_PtrSize,"UPtr"),NumPut(Color,CHOOSECOLOR,3*A_PtrSize,"UInt"),NumPut(3,CHOOSECOLOR,5*A_PtrSize,"UInt"),NumPut(&cccc,CHOOSECOLOR,4*A_PtrSize,"UPtr")
  395. ret:=DllCall("comdlg32\ChooseColorW","UPtr",&CHOOSECOLOR,"UInt")
  396. colors:=[]
  397. Loop,16
  398. colors["color" A_Index]:=NumGet(cccc,(A_Index-1)*4,"UInt")
  399. settings.Add({path:"colors",att:colors})
  400. if !ret
  401. exit
  402. return NumGet(CHOOSECOLOR,3*A_PtrSize)
  403. }
  404. MakeBackground(){
  405. ea:=settings.ea("//settings/grid"),Dot:=ea.Dot?ea.Dot:0,Grid:=ea.Grid!=""?ea.Grid:0xAAAAAA
  406. dot:=RGB(dot),Grid:=RGB(Grid)
  407. Image:=ComObjCreate("WIA.ImageFile"),vector:=ComObjCreate("WIA.Vector"),Dot+=0,Grid+=0,vector.add(Dot)
  408. loop,99
  409. vector.add(Grid)
  410. Image:=vector.Imagefile(10,10)
  411. FileDelete,tile.bmp
  412. Image.savefile("tile.bmp"),Display_Grid("removebrush")
  413. WinSet,Redraw,,% hwnd([3])
  414. }
  415. GetInfo(hotkey){
  416. MouseGetPos,x,y
  417. xx:=x,yy:=y
  418. ControlGetPos,cx,cy,cw,ch,,% hwnd([3])
  419. if (x>cx&&x<cx+cw&&y>cy+v.Caption&&y<cy+ch){
  420. x:=x-cx,y:=y-cy
  421. Grid(x,y,1)
  422. }else
  423. x:=0,y:=0
  424. value:=hotkey="TreeView"?"":Hotkey="DateTime"?"LongDate":Hotkey="Progress"?100:Hotkey
  425. if (hotkey="picture"){
  426. FileSelectFile,value,,,Select an image,*.bmp;*.jpg;*.gif;*.png
  427. if (ErrorLevel||value="")
  428. return
  429. if !FileExist(value)
  430. return
  431. }
  432. undo.add()
  433. control:=window.add({path:"gui/window/control",att:{type:hotkey,x:x,y:y,value:value},dup:1})
  434. pos:=WinPos(xx,yy),con:=window.ssn("//*[@x<" pos.x " and @x+@w>" pos.x " and @y<" pos.y " and @y+@h>" pos.y " and @type='Tab' or @type='Tab2']")
  435. if(con){
  436. tt:=xml.ea(con),nn:=GetClassNN(tt.hwnd)
  437. top:=window.ssn("//control[@hwnd='" tt.hwnd "']")
  438. ControlGet,tabnum,tab,,%nn%,% hwnd([3])
  439. Gui,3:Tab,%tabnum%,% SubStr(nn,16)
  440. if !tb:=ssn(top,"tab[@tab='" tabnum "']")
  441. tb:=window.under({under:top,node:"tab",att:{tab:tabnum,hwnd:tt.hwnd}})
  442. tb.SetAttribute("hwnd",tt.hwnd)
  443. tb.AppendChild(control)
  444. new:=AddControl(control)
  445. }else
  446. new:=AddControl(control)
  447. debug(),eval(),undo.redo:=[]
  448. }
  449. Convert_Hotkey(key){
  450. StringUpper,key,key
  451. for a,b in [{Shift:"+"},{Ctrl:"^"},{Alt:"!"}]
  452. for c,d in b
  453. key:=RegExReplace(key,"\" d,c "+")
  454. return key
  455. }
  456. RGB(c){
  457. SetFormat,IntegerFast,H
  458. c:=(c&255)<<16|(c&65280)|(c>>16),c:=SubStr(c,1)
  459. SetFormat,IntegerFast,D
  460. return c
  461. }
  462. Display_Grid(x:=""){
  463. Static wBrush
  464. if (x="removebrush")
  465. wBrush:=""
  466. if(A_Gui!=3)
  467. return
  468. if settings.ssn("//options/Display_Grid").text
  469. tile:="tile.bmp"
  470. else
  471. return
  472. If !wBrush
  473. wBrush:=DllCall("CreatePatternBrush",UInt,DllCall("LoadImage",Int,0,Str,"tile.bmp",Int,0,Int,0,Int,0,UInt,0x2010,"UInt"),"UInt")
  474. Return wBrush
  475. }
  476. Grid(ByRef x,ByRef y,adjust:=0){
  477. if adjust
  478. x-=v.Border,y-=v.border+v.caption
  479. if settings.ssn("//options/Snap_To_Grid").text
  480. x:=Round(x,-1),y:=Round(y,-1)
  481. }
  482. AddControl(info){
  483. ea:=xml.ea(info)
  484. for a,b in {x:ea.x,y:ea.y,w:ea.w,h:ea.h}
  485. if(b~="\d")
  486. pos.=a b " "
  487. if(ea.type="ListView")
  488. pos.=" -Multi"
  489. value:=ea.value~="(ComboBox|DDL|DropDownList)"?ea.value "||":ea.value
  490. notify:=(ea.type~="Tab")?"gtabnotify":""
  491. if(ea.font){
  492. Gui,3:Font,% CompileFont(info),% ea.font
  493. Gui,3:Add,% ea.type,%pos% hwndhwnd %notify% %Disable%,% value
  494. Gui,3:Font
  495. }else{
  496. Gui,3:Add,% ea.type,%pos% hwndhwnd %notify% %disable%,% value
  497. }
  498. if(ea.type="TreeView"){
  499. Gui,3:Default
  500. TV_Add("Treeview (Placeholder)")
  501. }if(InStr(ea.type,"tab"))
  502. Gui,3:Tab
  503. ControlGetPos,x,y,w,h,,ahk_id%hwnd%
  504. wh:=!(ea.type~="(ComboBox|DDL|DropDownList)")?[["w",w],["h",h]]:[["w",w]]
  505. for a,b in wh
  506. info.SetAttribute(b.1,b.2)
  507. info.SetAttribute("hwnd",hwnd+0)
  508. WinGet,cl,ControlListHWND,% hwnd([3])
  509. if(ea.type~="ComboBox|ListView|DropDownList|DDL"){
  510. for a,b in StrSplit(cl,"`n")
  511. if !window.ssn("//*[@hwnd='" b+0 "']")
  512. info.SetAttribute("married",b+0)
  513. }
  514. debug()
  515. return info
  516. }
  517. Debug(info:=""){
  518. if(info=0)
  519. if(hwnd(55))
  520. return hwnd({rem:55})
  521. if !settings.ssn("//options/Debug_Window").text
  522. return
  523. if !hwnd(55){
  524. Gui,55:Destroy
  525. Gui,55:Default
  526. Gui,+hwndhwnd +Resize
  527. hwnd(55,hwnd)
  528. Gui,Margin,0,0
  529. Gui,Add,Edit,x0 y0 w900 h300 -Wrap
  530. Gui,Show,x0 y0 NA,Debug
  531. Gui,1:+AlwaysOnTop
  532. Gui,1:-AlwaysOnTop
  533. }
  534. info:=info?info:window
  535. Loop,2
  536. info.Transform()
  537. text:=info[]?info[]:window[]
  538. ControlSetText,Edit1,%text%,% hwnd([55])
  539. return
  540. 55GuiEscape:
  541. 55GuiClose:
  542. hwnd({rem:55})
  543. return
  544. 55GuiSize:
  545. GuiControl,55:Move,Edit1,w%A_GuiWidth% h%A_GuiHeight%
  546. return
  547. }
  548. tv(){
  549. tv:
  550. if(A_GuiEvent!="Normal")
  551. return
  552. if((current:=TreeView.ssn("//*[@tv='" A_EventInfo "']")).ParentNode.nodename="Add"){
  553. GetInfo(current.nodename)
  554. }else if(tv:=treeview.ssn("//*[@tv='" A_EventInfo "']")){
  555. ea:=xml.ea(tv),Control:=window.ssn("//*[@hwnd='" ssn(tv.ParentNode,"@hwnd").text "']"),ItemInfo:=xml.ea(Control),undo.add()
  556. if (ea.value~="(x|y|w|h)"){
  557. InputBox,newvalue,Enter a new value,% "Enter a new value for " conxml.ssn("//*[@value='" ea.value "']/@desc").text,,,,,,,,% ItemInfo[ea.value]
  558. if ErrorLevel
  559. return
  560. if RegExMatch(newvalue,"\D")
  561. return m("Must be an integer")
  562. Gui,2:Default
  563. if (tv.ParentNode.nodename="all"){
  564. sel:=window.sn("//control[@selected='1']")
  565. while,Control:=sel.Item[A_Index-1]{
  566. Control.SetAttribute(ea.value,newvalue),new:=xml.ea(Control)
  567. info:=treeview.ssn("//*[@hwnd='" new.hwnd "']/*[@value='" ea.value "']"),info:=xml.ea(info)
  568. TV_Modify(info.tv,"",info.desc " = " newvalue)
  569. GuiControl,3:movedraw,% new.hwnd,% ea.value newvalue
  570. }
  571. }else{
  572. Control:=window.ssn("//*[@hwnd='" ssn(tv.ParentNode,"@hwnd").text "']")
  573. info:=treeview.ssn("//*[@hwnd='" ssn(control,"@hwnd").text "']/*[@value='" ea.value "']"),info:=xml.ea(info)
  574. TV_Modify(info.tv,"",info.desc " = " newvalue)
  575. Control.SetAttribute(ea.value,newvalue),new:=xml.ea(Control)
  576. GuiControl,3:movedraw,% new.hwnd,% ea.value newvalue
  577. }
  578. }else if(ea.value~="\b(v|g)\b"){
  579. InputBox,newvalue,Enter a new value,% "Enter a new value for " conxml.ssn("//*[@value='" ea.value "']/@desc").text,,,,,,,,% ItemInfo[ea.value]
  580. if ErrorLevel
  581. return
  582. newvalue:=clean(newvalue)
  583. if(ea.value="g"){
  584. sel:=window.sn("//control[@selected='1']")
  585. while,ss:=sel.Item[A_Index-1]{
  586. if label:=window.ssn("//label[@name='" ssn(ss,"@g").text "']"){
  587. if(newvalue="")
  588. label.ParentNode.RemoveChild(label)
  589. else
  590. label.SetAttribute("name",newvalue)
  591. }
  592. tv:=TreeView.ssn("//*[@hwnd='" ssn(ss,"@hwnd").text "']/info[@value='g']/@tv").text
  593. if(newvalue="")
  594. ss.RemoveAttribute("g"),TV_Modify(tv,"","G-Label")
  595. else
  596. ss.SetAttribute("g",newvalue)TV_Modify(tv,"","G-Label = " newvalue)
  597. }
  598. }if(ea.value="v"){
  599. tv:=TreeView.ssn("//*[@hwnd='" ssn(Control,"@hwnd").text "']/info[@value='v']/@tv").text
  600. if(newvalue="")
  601. Control.RemoveAttribute("v"),TV_Modify(tv,"","Variable")
  602. else
  603. Control.SetAttribute("v",newvalue)TV_Modify(tv,"","Variable = " newvalue)
  604.  
  605. }
  606. }else if(ea.value="font"){
  607. ea:=xml.ea(control)
  608. if !ea.font
  609. ea:=window.ea("//control[@selected='1']")
  610. dlg_font(ea,1,hwnd(1))
  611. selected:=window.sn("//control[@selected='1']")
  612. while,Control:=selected.Item[A_Index-1]{
  613. for a,b in ea
  614. if(a~="i)(bold|italic|strikeout|color|font|size|underline)")
  615. Control.SetAttribute(a,b)
  616. con:=xml.ea(Control)
  617. style:=CompileFont(Control),name:=ea.font
  618. Gui,3:Font
  619. Gui,3:Font,%style%,%name%
  620. GuiControl,3:Font,% con.hwnd
  621. GuiControl,% "3:+c" ea.color,% con.hwnd
  622. WinSet,Redraw,,% hwnd([3])
  623. Gui,3:Font
  624. }}else if(ea.value="value"){
  625. InputBox,new,Input Required,% "Input a new value for " ea.desc,,,,,,,,% ItemInfo[ea.value]
  626. if ErrorLevel
  627. return
  628. ea:=xml.ea(control),control.SetAttribute("value",new)
  629. GuiControl,3:,% ea.hwnd,% _:=ea.value~="i)tab|tab2|ComboBox|DropDownList"?"|" new:new
  630. if((iteminfo.type="ComboBox"||iteminfo.type="DropDownList")&&!InStr(new,"||"))
  631. GuiControl,3:Choose,% ea.hwnd,1
  632. if(StrSplit(new,"|").MaxIndex()<sn(control,"tab").length){
  633. m("This feature 'should' be asking if you want to get rid of the controls on the tabs you are removing....")
  634. }
  635. if(iteminfo.type~="Tab"){
  636. for a,b in StrSplit(new,"|")
  637. if(!ssn(control,"tab[@tab='" a "']"))
  638. tb:=window.under({under:control,node:"tab",att:{tab:a}}),
  639. }
  640. Debug()
  641. }else if(ea.value="option"){
  642. InputBox,new,Additional Options,% "Input a value for" ea.desc,,,,,,,,% ItemInfo[ea.value]
  643. if ErrorLevel
  644. return
  645. control.SetAttribute("option",new),ea:=xml.ea(control)
  646. }
  647. else if(tv.nodename="windowtitle"){
  648. node:=window.ssn("//window")
  649. InputBox,new,Enter New Name,Please enter the new name for the window title,,,,,,,,% ssn(node,"@windowtitle").text
  650. if(ErrorLevel)
  651. return
  652. node.SetAttribute("windowtitle",new)
  653. }
  654. else if(tv.nodename="windowname"){
  655. node:=window.ssn("//window")
  656. InputBox,new,Enter New Name,Please enter the new name for the window title,,,,,,,,% ssn(node,"@windowname").text
  657. if(ErrorLevel)
  658. return
  659. node.SetAttribute("windowname",Clean(new))
  660. }
  661. Highlight(),DisplaySelected()
  662. SetTimer,Redraw,-100
  663. }
  664. return
  665. }
  666. Highlight(a:=""){
  667. if(A_Gui>3&&a!="show")
  668. return
  669. hwnd({rem:99})
  670. Gui,99:+LastFound +owner1 +E0x20 -Caption +hwndsh
  671. hwnd(99,sh)
  672. WinSet,TransColor,0xF0F0F0 100
  673. Gui,99:Color,0xF0F0F0,0xFF
  674. Gui,99:Default
  675. WinGetPos,x,y,w,h,% hwnd([3])
  676. x+=v.Border,y+=v.border+v.Caption,h-=(v.Border*2)+(v.Caption),w-=(v.Border*2)
  677. Gui,99:Show,x%x% y%y% w%w% h%h% NoActivate
  678. ll:=window.sn("//control[@selected='1']/@hwnd")
  679. while,l:=ll.item(A_Index-1).text{
  680. ControlGetPos,cx,cy,w,h,,ahk_id%l%
  681. if (cx&&cy&&w&&h){
  682. pos:=WinPos(cx,cy)
  683. Gui,Add,Progress,% "c" color " x" pos.x " y" pos.y " w" w " h" h,100
  684. }
  685. }
  686. if a=0
  687. SetTimer,Redraw,-10
  688. }
  689. Redraw(win:=3){
  690. WinSet,Redraw,,% hwnd([win])
  691. }
  692. Exit(close:=0){
  693. GuiClose:
  694. WinGetPos,xx,yy,w,h,% hwnd([1])
  695. adj:=adjust(xx,yy,w,h),att:={main:{x:xx,y:yy,w:adj.w,h:adj.h-v.menu}}
  696. for a,b in {settings:2,workarea:3}{
  697. ControlGetPos,x,y,w,h,,% hwnd([b])
  698. adjust:=adjust(x,y,w,h)
  699. att[a]:={x:adjust.x,y:adjust.y-v.menu,w:adjust.w,h:adjust.h}
  700. }
  701. for a,b in att
  702. settings.Add({path:"gui/" a,att:att[a]})
  703. file:=window.ssn("//filename").text
  704. settings.Add({path:"last",text:file}),settings.save(1)
  705. temp:=new xml("project",file),rem:=window.sn("//*")
  706. while,rr:=rem.Item[A_Index-1]
  707. for a,b in StrSplit("offsetx,offsety,married,hwnd,ow,oh",",")
  708. rr.RemoveAttribute(b)
  709. if !(temp[]==window[]){
  710. MsgBox,35,File Changed,Would you like to save your GUI?
  711. if !FileExist(file)
  712. rem:=window.ssn("//filename"),rem.ParentNode.RemoveChild(rem)
  713. IfMsgBox,Yes
  714. save()
  715. IfMsgBox,Cancel
  716. return
  717. }
  718. if(close)
  719. return new()
  720. ExitApp
  721. return
  722. }
  723. Hotkeys(state:=1){
  724. state:=state?"On":"Off"
  725. Hotkey,IfWinActive,% hwnd([1])
  726. hotkey:=settings.sn("//hotkeys/*[@hotkey!='']/@hotkey")
  727. while,key:=hotkey.item[A_Index-1].text
  728. Hotkey,%key%,hotkey,%state%
  729. return
  730. hotkey:
  731. hotkey:=settings.ssn("//*[@hotkey='" A_ThisHotkey "']").NodeName
  732. MouseGetPos,,,,Control,2
  733. if(control+0!=hwnd(3))
  734. if(window.ssn("//*[@hwnd='" control+0 "']/@type")~="i)Tab|Tab2|ComboBox"=0){
  735. ControlSend,,{%A_ThisHotkey%},ahk_id%control%
  736. return
  737. }
  738. if IsFunc(hotkey)
  739. %hotkey%()
  740. else if(hotkey~="(" Menu({menu:1}).add ")")
  741. getinfo(hotkey)
  742. return
  743. }
  744. Edit_Hotkeys(){
  745. static tv:=[]
  746. Gui,4:Destroy
  747. Gui,4:Default
  748. Gui,Add,TreeView,w300 r20
  749. Gui,Add,Button,gedithotkey Default,Edit Hotkey
  750. menu:=Menu({menu:1}),tv:=[],hotkeys(0)
  751. for a,b in Menu.order{
  752. for c,d in StrSplit(Menu[b],"|"){
  753. if !tv[b]
  754. root:=tv[b]:=TV_Add(b)
  755. if !(settings.ssn("//hotkeys/" clean(d)))
  756. settings.Add({path:"hotkeys/" clean(d),att:{menu:d}})
  757. tv[TV_Add(GetMenuItem(d,1),root,"Vis")]:={parent:b,xml:settings.ssn("//hotkeys/" clean(d))}
  758. }
  759. }
  760. TV_Modify(TV_GetChild(0),"Select Vis Focus")
  761. Gui,4:Show,,Hotkeys
  762. return
  763. 4GuiEscape:
  764. Gui,4:Destroy
  765. hotkeys()
  766. return
  767. edithotkey:
  768. Gui,4:Default
  769. value:=tv[TV_GetSelection()]
  770. oldmenu:=GetMenuItem(ssn(value.xml,"@menu").text)
  771. InputBox,new,New Hotkey,Enter a new hotkey,,,,,,,,% ssn(value.xml,"@hotkey").text
  772. if ErrorLevel
  773. return
  774. value.xml.SetAttribute("hotkey",new)
  775. newmenu:=GetMenuItem(ssn(value.xml,"@menu").text)
  776. Menu,% value.parent,Rename,%oldmenu%,%newmenu%
  777. TV_Modify(TV_GetSelection(),"",GetMenuItem(ssn(value.xml,"@menu").text,1))
  778. return
  779. }
  780. Adjust(ByRef x,byref y,w:="",h:=""){
  781. if (IsObject(x)=0&&y!=""&&x!=""&&w&&h)
  782. return {x:x-v.Border,y:y-(v.Border+v.Caption),w:w-(v.border*2),h:h-(v.border*2+v.Caption)}
  783. if (IsObject(x)=0&&y&&x)
  784. return {x:x-v.Border,y:y-(v.Border+v.Caption)}
  785. }
  786. New(){
  787. Gui,3:Destroy
  788. Gui,3:+Resize +hwndhwnd -0x20000 -0x10000 +parent1 -ToolWindow
  789. hwnd(3,hwnd),ea:=settings.ea("//gui/workarea"),pos:=""
  790. Gui,3:Show,% guipos("//gui/workarea","x176 y5 w500 h500"),Work Area
  791. Gui,3:Margin,0,0
  792. window:=new xml("gui"),Display_Grid(),Select(0,0)
  793. WinSet,Redraw,,% hwnd([3])
  794. }
  795. Save(filename:=""){
  796. if !FileExist("Projects")
  797. FileCreateDir,Projects
  798. Loop,2
  799. window.Transform()
  800. if !(filename){
  801. if !filename:=window.ssn("//filename").text
  802. FileSelectFile,filename,S16,%A_ScriptDir%\Projects,Save Project As,*.xml
  803. if ErrorLevel
  804. return
  805. filename:=InStr(filename,".xml")?filename:filename ".xml"
  806. }
  807. window.Add({path:"filename",text:filename}),filename:=SubStr(filename,-3)!=".xml"?filename ".xml":filename,window.file:=filename
  808. ControlGetPos,x,y,w,h,,% hwnd([3])
  809. att:={x:x,y:y,w:w,h:h},window.add({path:"workarea",att:att}),window.Transform(),window.save(1)
  810. SplitPath,filename,file
  811. TrayTip,GUI Creator,File '%file%' has been saved
  812. WinSetTitle,% hwnd([1]),,GUI Creator: %file%
  813. debug()
  814. }
  815. Move(){
  816. MouseGetPos,x,y,win,Ctrl,2
  817. pos:=WinPos(x,y),moved:=0,ctrl+=0,xx:=x,yy:=y,lastx:=x,lasty:=y
  818. if !control:=window.ssn("//*[@hwnd='" ctrl "' or @married='" ctrl "']")
  819. control:=window.ssn("//window/*[@x<" pos.x " and @y<" pos.y " and @x+@w>" pos.x " and @y+@h>" pos.y "]")
  820. if(ctrl=hwnd(3)&&control.xml="")
  821. return pos:=WinPos(x,y),Select(pos.x,pos.y)
  822. if((control.nodename!="control")||(win!=hwnd(1)||ctrl=hwnd("tv")))
  823. return
  824. Gui,99:Destroy
  825. if(control+0=hwnd("tv"))
  826. return
  827. ea:=xml.ea(control)
  828. list:=ea.selected?window.sn("//control[@selected='1']/descendant-or-self::control"):window.sn("//control[@hwnd='" ea.hwnd "']/descendant-or-self::control")
  829. while,ll:=list.Item[A_Index-1]
  830. ea:=xml.ea(ll),ll.SetAttribute("offsetx",ea.x-pos.x),ll.SetAttribute("offsety",ea.y-pos.y)
  831. if(list.length){
  832. while,GetKeyState("LButton"){
  833. MouseGetPos,xx,yy
  834. if(Abs(x-xx)>3||Abs(y-yy)>3){
  835. while,ll:=list.item[A_Index-1],ea:=xml.ea(ll)
  836. if(ea.type="DropDownList")
  837. SendMessage,0x14F,0,0,,% "ahk_id" ea.hwnd
  838. undo.add()
  839. break
  840. }
  841. }
  842. if(Abs(x-xx)=0&&Abs(y-yy)=0)
  843. return CreateSelection(window.sn("//*[@hwnd='" ssn(control,"@hwnd").text "']"))
  844. if(GetKeyState("shift")){
  845. SetTimer,Resize,-1
  846. return
  847. }
  848. while,GetKeyState("LButton"){
  849. MouseGetPos,xx,yy
  850. if(Abs(lastx-xx)>0||Abs(lasty-yy)>0){
  851. pos:=WinPos(xx,yy)
  852. while,ll:=list.Item[A_Index-1],ea:=xml.ea(ll){
  853. nx:=pos.x+ea.offsetx,ny:=pos.y+ea.offsety,Grid(nx,ny)
  854. GuiControl,3:MoveDraw,% ea.hwnd,% "x" nx " y" ny
  855. ll.SetAttribute("x",nx),ll.SetAttribute("y",ny)
  856. }
  857. }
  858. lastx:=xx,lasty:=yy
  859. }
  860. }
  861. pos:=WinPos(xx,yy),con:=window.ssn("//*[@x<" pos.x " and @x+@w>" pos.x " and @y<" pos.y " and @y+@h>" pos.y " and @type='Tab' or @type='Tab2']")
  862. if con
  863. AddToTab(con,list)
  864. UpdateTV(list),Eval(),highlight(),debug(),DisplaySelected()
  865. return
  866. }
  867. Select(xx,yy){
  868. Random,Color,0xcccccc,0xeeeeee
  869. Gui,59:-Caption +AlwaysOnTop +E0x20 +hwndselect +Owner1
  870. WinGetPos,wx,wy,ww,wh,% hwnd([3])
  871. WinGetPos,mx,my,,,% hwnd([1])
  872. Gui,59:Color,%Color%
  873. Gui,59:Show,% "x" wx+v.border " y" wy+v.border+v.caption " w" ww-(v.border*2) " h" wh-(v.border*2)-v.Caption " noactivate hide"
  874. Gui,59:Show,NoActivate
  875. WinSet,Transparent,50,ahk_id%select%
  876. while,GetKeyState("LButton"){
  877. MouseGetPos,x,y
  878. x:=x-(wx-mx)-v.Border,y:=y-(wy-my)-v.Border-v.Caption
  879. WinSet,Region,%xx%-%yy% %x%-%yy% %x%-%y% %xx%-%y% %xx%-%yy%,ahk_id %select%
  880. }
  881. start:={x:xx,y:yy},end:={x:x,y:y},pos:=[],pos.x:=[],pos.y:=[]
  882. for a,b in [start,end]
  883. pos.x[b.x]:=1,pos.y[b.y]:=1
  884. Gui,59:Destroy
  885. List:=window.sn("//*[@x>" pos.x.MinIndex() " and @x<" pos.x.MaxIndex() " and @y>" pos.y.MinIndex() " and @y<" pos.y.MaxIndex() "]"),CreateSelection(list)
  886. }
  887. CreateSelection(selections,toggle:=0){
  888. if ((GetKeyState("Control","P")=0&&GetKeyState("Shift","P")=0)&&toggle=0){
  889. sel:=window.sn("//window/descendant::control[@selected]")
  890. while,ss:=sel.Item[A_Index-1]
  891. ss.RemoveAttribute("selected")
  892. }
  893. while,ss:=selections.item[A_Index-1]{
  894. if(ss.nodename!="control")
  895. Continue
  896. if ((GetKeyState("Control","P")||toggle)&&ssn(ss,"@selected").text)
  897. ss.RemoveAttribute("selected")
  898. else
  899. ss.SetAttribute("selected",1)
  900. }
  901. highlight(),DisplaySelected(),debug()
  902. }
  903. Inside(inside){
  904. pos:=xml.ea(inside)
  905. return window.sn("//*[@x>" pos.x " and @x<" pos.x+pos.w " and @y>" pos.y " and @y<" pos.y+pos.h "]")
  906. }
  907. DisplaySelected(){
  908. static lastselected,type:={windowname:"Window Name",windowtitle:"Window Title"}
  909. selected:=window.sn("//control[@selected='1']"),top:=TreeView.ssn("//selected")
  910. Gui,2:Default
  911. GuiControl,2:-Redraw,SysTreeView321
  912. sel:=TreeView.sn("//control")
  913. while,ss:=sel.Item[A_Index-1]
  914. if !window.ssn("//*[@hwnd='" ssn(ss,"@hwnd").text "']/@selected")
  915. TV_Delete(ssn(ss,"@tv").text),ss.ParentNode.RemoveChild(ss)
  916. if(selected.length>1){
  917. if all:=TreeView.ssn("//all")
  918. TV_Delete(ssn(all,"@tv").text),all.ParentNode.RemoveChild(all)
  919. all:=TreeView.under({under:top,node:"all",att:{tv:TV_Add("All Controls",ssn(top,"@tv").text,"First")}})
  920. constants:=conxml.sn("//constants/info")
  921. while,cc:=constants.Item[A_Index-1]
  922. if !ssn(all,"*[@value='" ssn(cc,"@value").text "']")
  923. TreeView.under({under:all,node:"allset",att:{value:ssn(cc,"@value").text,tv:TV_Add(ssn(cc,"@desc").text,ssn(all,"@tv").text)}})
  924. while,ss:=selected.Item[A_Index-1]{
  925. ea:=xml.ea(ss),info:=xml.ea(conxml.ssn("//" ea.type)),info.v:=1,info.value:=1
  926. for a in info
  927. if rem:=TreeView.ssn("//allset[@value='" a "']")
  928. TV_Delete(ssn(rem,"@tv").text),rem.ParentNode.RemoveChild(rem)
  929. }
  930. TV_Modify(ssn(all,"@tv").text,"Expand")
  931. }else if(selected.length<=1)
  932. if all:=TreeView.ssn("//all")
  933. TV_Delete(ssn(all,"@tv").text),all.ParentNode.RemoveChild(all)
  934. /*
  935. Work on:
  936. -Add all of the main info to the control itself
  937. --Add optional stuff below it like all of the extra settings for the controls
  938. -Fix the "All" edits in the tv
  939. --make it move all the selected stuff.
  940. */
  941. while,ss:=selected.Item[A_Index-1],ea:=xml.ea(ss){
  942. if !tvi:=TreeView.ssn("//control[@hwnd='" ssn(ss,"@hwnd").text "']"){
  943. constants:=conxml.sn("//" ea.type "/constants|//constants/*"),rem:=xml.ea(conxml.ssn("//" ea.type))
  944. next:=TreeView.under({under:top,node:"control",att:{hwnd:ea.hwnd,tv:TV_Add(ea.type,ssn(top,"@tv").text,"Vis")}})
  945. while,cc:=constants.Item[A_Index-1],cea:=xml.ea(cc)
  946. if !rem[cea.value]
  947. value:=(vv:=ssn(ss,"@" cea.value).text)?cea.desc " = " vv:cea.desc,TreeView.under({under:next,node:"info",att:{tv:TV_Add(value,ssn(next,"@tv").text),value:cea.value,desc:cea.desc}})
  948. TV_Modify(ssn(next,"@tv").text,"Expand")
  949. }else{
  950. set:=sn(tvi,"descendant::*")
  951. while,sc:=set.item[A_Index-1],sa:=xml.ea(sc)
  952. TV_Modify(sa.tv,"",sa.desc _:=ea[sa.value]?" = " ea[sa.value]:"")
  953. }
  954. }
  955. ea:=xml.ea(window.ssn("//window"))
  956. for a,b in ea{
  957. text:=b?type[a] " = " b:type[a]
  958. node:=TreeView.ssn("//" a)
  959. TV_Modify(ssn(node,"@tv").text,"",text)
  960. }
  961. GuiControl,2:+Redraw,SysTreeView321
  962. TV_Modify(TreeView.ssn("//Add/@tv").text,selected.length?"-Expand":"Expand"),Highlight()
  963. }
  964. KillSelect(){
  965. Gui,99:Destroy
  966. }
  967. Select_All(){
  968. SelectAll:
  969. all:=window.sn("//window/descendant::control")
  970. while,aa:=all.Item[A_Index-1],ea:=xml.ea(aa){
  971. if InStr(A_ThisHotkey,"+")
  972. ea.selected?aa.RemoveAttribute("selected"):aa.SetAttribute("selected",1)
  973. else
  974. aa.SetAttribute("selected",1)
  975. }
  976. Highlight(),DisplaySelected()
  977. return
  978. }
  979. Save_As(){
  980. filename:=window.ssn("//filename").text
  981. SplitPath,filename,,dir
  982. FileSelectFile,filename,,%dir%,Save Window As,*.xml
  983. if !(ErrorLevel){
  984. window.ssn("//filename").text:=filename
  985. save()
  986. }
  987. }
  988. LButton(){
  989. SetTimer,lb,-1
  990. return
  991. lb:
  992. MouseGetPos,x,y,win,ctrl,2
  993. node:=window.ssn("//*[@hwnd='" ctrl+0 "']"),ea:=xml.ea(node)
  994. if(ssn(node,"@type").text~="Tab"){
  995. Sleep,80
  996. if(v.tabbutton)
  997. return v.tabbutton:=0
  998. }
  999. SetTimer,move,-1
  1000. return
  1001. }
  1002. Edit_GLabels(){
  1003. if !window.sn("//*[@g!='']").length
  1004. return m("This project does not have any labels associated with any of the controls","Please add label associations first")
  1005. Gui,99:Destroy
  1006. Gui,5:Destroy
  1007. Gui,5:Default
  1008. Gui,5:+hwndhwnd
  1009. hwnd(5,hwnd)
  1010. Gui,Add,ListView,w100 h400 AltSubmit gegl,Labels
  1011. Gui,Add,Edit,x+10 w500 h400 geditgl
  1012. labels:=window.sn("//@g")
  1013. while,ll:=labels.item[A_Index-1]{
  1014. if !window.ssn("//labels/label[@name='" ll.text "']")
  1015. window.add({path:"labels/label",att:{name:ll.text},dup:1})
  1016. }
  1017. labels:=window.sn("//labels/label")
  1018. while,ll:=labels.Item[A_Index-1]{
  1019. if !window.ssn("//*[@g='" ssn(ll,"@name").text "']")
  1020. ll.ParentNode.RemoveChild(ll)
  1021. else
  1022. LV_Add("",ssn(ll,"@name").text)
  1023. }
  1024. WinGetPos,x,y,w,h,% hwnd([1])
  1025. Gui,5:Show,% Center(5),Label Editor
  1026. LV_Modify(1,"Select Vis Focus")
  1027. return
  1028. editgl:
  1029. if !LV_GetNext()
  1030. return
  1031. LV_GetText(label,LV_GetNext())
  1032. if !info:=window.ssn("//labels/label[@name='" label "']")
  1033. info:=window.add({path:"labels/label",att:{name:label},dup:1})
  1034. ControlGetText,text,Edit1,% hwnd([5])
  1035. info.text:=text
  1036. return
  1037. egl:
  1038. if !LV_GetNext()
  1039. return
  1040. LV_GetText(label,LV_GetNext())
  1041. text:=window.ssn("//label[@name='" label "']").text
  1042. ControlSetText,Edit1,%text%,% hwnd([5])
  1043. return
  1044. 5GuiClose:
  1045. 5GuiEscape:
  1046. Gui,5:Destroy
  1047. Highlight("show")
  1048. return
  1049. }
  1050. Center(hwnd){
  1051. Gui,%hwnd%:Show,Hide
  1052. WinGetPos,x,y,w,h,% hwnd([1])
  1053. WinGetPos,xx,yy,ww,hh,% hwnd([hwnd])
  1054. centerx:=(Abs(w-ww)/2),centery:=Abs(h-hh)/2
  1055. return "x" x+centerx " y" y+centery
  1056. }
  1057. Grid_Dot_Color(){
  1058. color:=settings.Add({path:"grid"})
  1059. dot:=Dlg_Color(ssn(color,"@dot").text,hwnd(1)),color.SetAttribute("dot",dot),MakeBackground(),settings.Add({path:"options/Grid",text:1})
  1060. }
  1061. Grid_Background(){
  1062. color:=settings.Add({path:"grid"})
  1063. dot:=Dlg_Color(ssn(color,"@grid").text,hwnd(1)),color.SetAttribute("grid",dot),MakeBackground(),settings.Add({path:"options/Grid",text:1})
  1064. }
  1065. Resize(){
  1066. static wia:=ComObjCreate("wia.imagefile")
  1067. MouseGetPos,x,y,win,Ctrl,2
  1068. pos:=WinPos(x,y),moved:=0,ctrl+=0,xx:=x,yy:=y,lastx:=x,lasty:=y
  1069. if !control:=window.ssn("//*[@hwnd='" ctrl "' or @married='" ctrl "']")
  1070. control:=window.ssn("//window/*[@x<" pos.x " and @y<" pos.y " and @x+@w>" pos.x " and @y+@h>" pos.y "]")
  1071. ea:=xml.ea(control)
  1072. list:=ea.selected?window.sn("//control[@selected='1']"):window.sn("//control[@hwnd='" ea.hwnd "']")
  1073. while,ll:=list.Item[A_Index-1],ea:=xml.ea(ll){
  1074. ControlGetPos,,,w,h,,% "ahk_id" ea.hwnd
  1075. ll.SetAttribute("ow",w),ll.SetAttribute("oh",h)
  1076. if(ea.width=""&&ea.height=""&&ea.type="Picture"){
  1077. wia.loadfile(ea.value)
  1078. for a,b in {width:wia.width,height:wia.height}
  1079. ll.SetAttribute(a,b)
  1080. }
  1081. }
  1082. while,GetKeyState("LButton"){
  1083. MouseGetPos,x,y
  1084. if(lastx=x&&lasty=y)
  1085. Continue
  1086. break
  1087. }
  1088. while,GetKeyState("LButton"){
  1089. MouseGetPos,x,y
  1090. if(lastx=x&&lasty=y)
  1091. Continue
  1092. while,ll:=list.Item[A_Index-1],ea:=xml.ea(ll){
  1093. nw:=x-xx,nh:=y-yy,Grid(nw,nh),command:="Move"
  1094. if(ea.type="Picture")
  1095. nh:=Round(nw*ea.height/ea.width),command:="MoveDraw"
  1096. GuiControl,3:%command%,% ea.hwnd,% "w" ea.ow+nw " h" ea.oh+nh
  1097. ll.SetAttribute("w",ea.ow+nw),ll.SetAttribute("h",ea.oh+nh)
  1098. lastx:=x,lasty:=y
  1099. }
  1100. }
  1101. Highlight(),eval(),DisplaySelected()
  1102. SetTimer,Redraw,-10
  1103. }
  1104. Update_Program(){
  1105. m("Coming soon (if not soon ask maestrith nicely)")
  1106. /*
  1107. if FileExist("gui.ahk")
  1108. return m("NO!")
  1109. FileMove,%A_ScriptName%,deleteme.ahk,1
  1110. UrlDownloadToFile,http://files.maestrith.com/GUI_Creator/GUI_Creator.ahk,%A_ScriptName%
  1111. FileDelete,deleteme.ahk
  1112. Reload
  1113. ExitApp
  1114. */
  1115. }
  1116. Dlg_Font(ByRef Style,Effects=1,window=""){
  1117. VarSetCapacity(LOGFONT,60),strput(style.font,&logfont+28,32,"CP0")
  1118. LogPixels:=DllCall("GetDeviceCaps","uint",DllCall("GetDC","uint",0),"uint",90),Effects:=0x041+(Effects?0x100:0)
  1119. for a,b in font:={16:"bold",20:"italic",21:"underline",22:"strikeout"}
  1120. if style[b]
  1121. NumPut(b="bold"?700:1,logfont,a)
  1122. style.size?NumPut(Floor(style.size*logpixels/72),logfont,0):NumPut(16,LOGFONT,0)
  1123. VarSetCapacity(CHOOSEFONT,60,0),NumPut(60,CHOOSEFONT,0),NumPut(&LOGFONT,CHOOSEFONT,12),NumPut(Effects,CHOOSEFONT,20),NumPut(RGB(style.color),CHOOSEFONT,24),NumPut(window,CHOOSEFONT,4)
  1124. if !r:=DllCall("comdlg32\ChooseFontA","uint",&CHOOSEFONT)
  1125. return
  1126. Color:=NumGet(CHOOSEFONT,24),bold:=NumGet(LOGFONT,16)>=700?1:0
  1127. style:={size:NumGet(CHOOSEFONT,16)//10,font:StrGet(&logfont+28,"CP0"),color:RGB(color)}
  1128. for a,b in font
  1129. style[b]:=NumGet(LOGFONT,a,"UChar")?1:0
  1130. style["bold"]:=bold
  1131. return 1
  1132. }
  1133. CompileFont(XMLObject,text:=1){
  1134. ea:=xml.ea(XMLObject),style:=[],name:=ea.name,styletext:="norm"
  1135. for a,b in {bold:"",color:"c",italic:"",size:"s",strikeout:"",underline:""}
  1136. if ea[a]
  1137. styletext.=" " _:=b?b ea[a]:a
  1138. style:=text?styletext:style
  1139. if(style="norm")
  1140. return
  1141. return style
  1142. }
  1143. Delete(){
  1144. all:=window.sn("//window/descendant::*[@selected='1']")
  1145. undo.add()
  1146. while,aa:=all.item[A_Index-1],ea:=xml.ea(aa)
  1147. DllCall("DestroyWindow",ptr,ea.hwnd),aa.ParentNode.RemoveChild(aa)
  1148. Select(0,0)
  1149. }
  1150. Eval(){
  1151. tab:=window.sn("descendant::control[@type='Tab' or @type='Tab2']"),list:=window.sn("//*[contains(@type,'Tab')]/descendant::control")
  1152. while,ll:=list.item[A_Index-1]{
  1153. parent:=ssn(ll,"ancestor::control[contains(@type,'Tab')]"),pa:=xml.ea(parent),ea:=xml.ea(ll)
  1154. if(!(ea.x>pa.x&&ea.x<pa.x+pa.w&&ea.y>pa.y&&ea.y<pa.y+pa.h)){
  1155. if new:=window.ssn("//control[contains(@type,'Tab')][@x<" ea.x " and @x+@y>" ea.x " and @y<" ea.y " and @y+@h>" ea.y "]"){
  1156. tt:=xml.ea(new),nn:=GetClassNN(tt.hwnd),top:=window.ssn("//control[@hwnd='" tt.hwnd "']")
  1157. ControlGet,tabnum,tab,,%nn%,% hwnd([3])
  1158. Gui,3:Tab,%tabnum%,% SubStr(nn,16)
  1159. if(!tb:=ssn(new,"tab[@tab='" tabnum "']")){
  1160. Loop,%tabnum%
  1161. if(!ssn(new,"tab[@tab='" A_Index "']"))
  1162. window.under({under:top,node:"tab",att:{tab:A_Index}})
  1163. tb:=ssn(new,"tab[@tab='" tabnum "']")
  1164. }
  1165. tb.AppendChild(ll),new:=AddControl(ll)
  1166. DllCall("DestroyWindow",ptr,ea.hwnd)
  1167. }else{
  1168. window.ssn("//window").AppendChild(ll)
  1169. Gui,3:Tab
  1170. DllCall("DestroyWindow",ptr,ea.hwnd),AddControl(ll)
  1171. }}}
  1172. gb:=window.sn("descendant::control[@type='GroupBox']"),inside:=[]
  1173. while,gg:=gb.item[A_Index-1]{
  1174. while,in:=inside(gg).item[A_Index-1],ea:=xml.ea(in){
  1175. if(gg.xml!=in.ParentNode.xml&&gg.ParentNode.xml=in.ParentNode.xml)
  1176. gg.AppendChild(in)
  1177. inside[ea.hwnd]:=1
  1178. }
  1179. }
  1180. ngb:=window.sn("//descendant::control[@type!='GroupBox' and @type!='Tab' and @type!='Tab2']")
  1181. while,move:=ngb.item[A_Index-1],ea:=xml.ea(move){
  1182. if(inside[ea.hwnd]!=1&&ssn(move.ParentNode,"@type").text="GroupBox")
  1183. move.ParentNode.ParentNode.AppendChild(move)
  1184. }
  1185. debug()
  1186. }
  1187. GetClassNN(ctrl){
  1188. WinGet,list,ControlList,% hwnd([3])
  1189. for a,b in StrSplit(list,"`n"){
  1190. ControlGet,hwnd,hwnd,,%b%,% hwnd([3])
  1191. if(hwnd=ctrl)
  1192. return b
  1193. }
  1194. }
  1195. UpdateTV(list){
  1196. while,ll:=list.Item[A_Index-1]{
  1197. if tv:=TreeView.ssn("//*[@hwnd='" ssn(ll,"@hwnd").text "']"){
  1198. x:=xml.ea(ssn(tv,"*[@value='x']")),y:=xml.ea(ssn(tv,"*[@value='y']"))
  1199. Gui,2:Default
  1200. for a,b in {x:[x.tv,x.desc],y:[y.tv,y.desc]}
  1201. TV_Modify(b.1,"",b.2 " = " ssn(ll,"@" a).text)
  1202. }
  1203. }
  1204. }
  1205. AddToTab(tab,list){
  1206. tt:=xml.ea(tab),nn:=GetClassNN(tt.hwnd)
  1207. top:=window.ssn("//control[@hwnd='" tt.hwnd "']")
  1208. ControlGet,tabnum,tab,,%nn%,% hwnd([3])
  1209. Gui,3:Tab,%tabnum%,% SubStr(nn,16)
  1210. while,ll:=list.item[A_Index-1],ea:=xml.ea(ll){
  1211. if(InStr(ea.type,"tab"))
  1212. Continue
  1213. if(ssn(ll,"ancestor::control[@type='Tab' or @type='Tab2']"))
  1214. Continue
  1215. if !tb:=ssn(top,"tab[@tab='" tabnum "']")
  1216. tb:=window.under({under:top,node:"tab",att:{tab:tabnum}})
  1217. tb.AppendChild(ll)
  1218. DllCall("DestroyWindow",ptr,ea.hwnd)
  1219. AddControl(ll)
  1220. }
  1221. debug()
  1222. }
  1223. UpdatePos(ctrl){
  1224. ControlGetPos,x,y,w,h,,% "ahk_id" xml.ea(ctrl).hwnd
  1225. pos:=WinPos(x,y)
  1226. for a,b in {x:pos.x,y:pos.y,w:w,h:h}
  1227. ctrl.SetAttribute(a,b)
  1228. window.transform(1)
  1229. }
  1230. Export(return:=0){
  1231. glabel:=[],winname:=window.ssn("//window/@name").text,program:=winname?"Gui," winname ":Default`n":"",main:=window.sn("//window/control"),top:=window.ssn("//window"),obj:=[]
  1232. while,mm:=main.item[A_Index-1],ea:=xml.ea(mm)
  1233. obj[ea.y,ea.x,ea.hwnd]:=mm
  1234. for a,b in obj
  1235. for c,d in b
  1236. for e,f in d
  1237. top.AppendChild(f)
  1238. obj:=[],gb:=window.sn("//*[@type='GroupBox']/*")
  1239. while,gg:=gb.item[A_Index-1],ea:=xml.ea(gg)
  1240. obj[ea.y,ea.x,ea.hwnd]:={parent:gg.ParentNode,item:gg}
  1241. for a,b in obj
  1242. for c,d in b
  1243. for e,f in d
  1244. f.parent.AppendChild(f.item)
  1245. tab:=[],tabs:=window.sn("//window/control[@type='Tab' or @type='Tab2']")
  1246. while,tt:=tabs.item[A_Index-1],ea:=xml.ea(tt)
  1247. tab[ea.y,ea.x,ea.hwnd]:=tt
  1248. for a,b in tab
  1249. for c,d in b
  1250. for e,f in d
  1251. top.AppendChild(f)
  1252. tabs:=window.sn("//*[@type='Tab' or @type='Tab2']/tab")
  1253. while,tt:=tabs.item[A_Index-1]{
  1254. items:=[],ctrls:=sn(tt,"control")
  1255. while,cc:=ctrls.item[A_Index-1],ea:=xml.ea(cc)
  1256. items[ea.y,ea.x,ea.hwnd]:=cc
  1257. for a,b in items
  1258. for c,d in b
  1259. for e,f in d
  1260. tt.AppendChild(f)
  1261. }
  1262. all:=window.sn("//window/descendant::*")
  1263. while,aa:=all.item[A_Index-1],ea:=xml.ea(aa){
  1264. if(aa.NodeName="tab"){
  1265. line:="Gui,Tab," ea.tab "`n"
  1266. program.=line
  1267. Continue
  1268. }
  1269. font:=CompileFont(aa)
  1270. if(ea.g)
  1271. glabel[ea.g]:=1
  1272. if(font!=lastfont&&font)
  1273. Program.="Gui,Font," font "," ea.font "`n"
  1274. if(font!=lastfont&&!font)
  1275. program.="Gui,Font`n"
  1276. Program.=CompileItem(aa) "`n",lastfont:=font
  1277. }
  1278. ;/Compile GUI
  1279. pos:=WinPos(),title:=window.ssn("//window/@windowtitle").text,title:=title?title:"Created with GUI Creator by maestrith"
  1280. Program.="Gui,Show,w" pos.w " h" pos.h "," title
  1281. /*
  1282. this needs to check cexml to see if the labels already exist
  1283. if it doesn't
  1284. create the labels below the ;/gui[] tag
  1285. else
  1286. they exist, duh, no need to add them :)
  1287. do a quick scan to be safe
  1288. */
  1289. for a in glabel
  1290. program.="`n" a ":`n" window.ssn("//labels/label[@name='" a "']").text "`nreturn"
  1291. /*
  1292. /yea, above thing
  1293. */
  1294. m("Text copied to your clipboard:",Clipboard:=program)
  1295. return
  1296.  
  1297.  
  1298.  
  1299.  
  1300. /*
  1301. ControlGetPos,,,w,h,,% hwnd([3])
  1302.  
  1303. program.="Gui,Show,w" w-(v.Border*2) " h" h-(v.Border*2+v.Caption) ",Created with GUI Creator by Maestrith :)`nreturn"
  1304. */
  1305. StringReplace,program,program,`n,`r`n,All
  1306. if(return)
  1307. return program
  1308. Clipboard:=program
  1309. TrayTip,GUI Creator,GUI Copied to the Clipboard
  1310. return
  1311. control:
  1312. ff:="Gui,Font," cf "," ea.font,_:=(cf="norm"&&lastfont="")?ff:="":(cf="norm"&&lastfont!="")?(ff:="Gui,Font",lastfont:="",program.=ff "`n"):(cf!="norm"&&ff!=lastfont)?(lastfont:=ff:="Gui,Font," cf "," ea.font,program.=ff "`n")
  1313. add:=""
  1314. for a,b in {v:ea.v,g:ea.g}
  1315. if(b)
  1316. add.=" " a b
  1317. program.="Gui,Add," ea.type ",x" ea.x " y" ea.y " w" ea.w " h" ea.h add "," ea.value "`n"
  1318. if ea.g
  1319. glabel[ea.g]:=1
  1320. return
  1321. }
  1322. Help(){
  1323. MsgBox,262176,Help,Left Click and drag to create a selection`n-Shift+Left Click to add items to the selection`n-Ctrl+Left Click to toggle the items selected state`n`nRight Click and drag to Resize selected controls`n`nCtrl+A to Select All and Ctrl+Shift+A to Toggle Select All`n`nTo delete selected controls press Delete
  1324. }
  1325. Test_GUI(){
  1326. DynaRun(Export(1))
  1327. }
  1328. DynaRun(Script,debug=0){
  1329. static exec
  1330. exec.terminate()
  1331. Name:="GUI Creator Test",Pipe:=[],cr:= Chr(34) Chr(96)"n" Chr(34)
  1332. script:="#SingleInstance,Force`n" script
  1333. script.="`nreturn`nguiescape:`nguiclose:`nexitapp`nreturn"
  1334. Loop, 2
  1335. Pipe[A_Index]:=DllCall("CreateNamedPipe","Str","\\.\pipe\" name,"UInt",2,"UInt",0,"UInt",255,"UInt",0,"UInt",0,"UPtr",0,"UPtr",0,"UPtr")
  1336. Call:=Chr(34) A_AhkPath Chr(34) " /ErrorStdOut /CP65001 " Chr(34) "\\.\pipe\" Name Chr(34),Shell:=ComObjCreate("WScript.Shell"),Exec:=Shell.Exec(Call)
  1337. for a,b in Pipe
  1338. DllCall("ConnectNamedPipe","UPtr",b,"UPtr",0)
  1339. FileOpen(Pipe[2],"h","UTF-8").Write(Script)
  1340. for a,b in Pipe
  1341. DllCall("CloseHandle","UPtr",b)
  1342. return exec
  1343. }
  1344. Undo(){
  1345. undo.undogo()
  1346. }
  1347. class undo{
  1348. undo:=[],redo:=[]
  1349. __New(){
  1350. undo.undo:=[],undo.redo:=[]
  1351. }
  1352. add(){
  1353. undo.undo.Insert(window.ssn("//*").clonenode(1))
  1354. }
  1355. undogo(){
  1356. undo.undo.1?undo.fix("undo","redo"):m("Nothing more to undo")
  1357. }
  1358. redogo(){
  1359. undo.redo.1?undo.fix("redo","undo"):m("Nothing more to redo")
  1360. }
  1361. fix(in,out){
  1362. last:=undo[in].pop(),list1:=window.sn("//control"),list2:=sn(last,"//control"),undo[out].Insert(window.ssn("//*").clonenode(1))
  1363. while,ll:=list1.item[A_Index-1],ea:=xml.ea(ll)
  1364. if !ssn(last,"//*[@hwnd='" ea.hwnd "']")
  1365. DllCall("DestroyWindow",ptr,ea.hwnd),ll.ParentNode.RemoveChild(ll),action:=1
  1366. while,ll:=list2.item[A_Index-1],ea:=xml.ea(ll)
  1367. if !window.ssn("//*[@hwnd='" ea.hwnd "']")
  1368. top:=ll.ParentNode.NodeName="window"?window.ssn("//window"):window.ssn("//*[@hwnd='" ssn(ll.ParentNode,"@hwnd").text "']"),top.AppendChild(ll),AddControl(ll),action:=1
  1369. while,ll:=list2.item[A_Index-1],ea:=xml.ea(ll){
  1370. ctrl:=window.ssn("//*[@hwnd='" ea.hwnd "']"),cea:=xml.ea(ctrl),move:=""
  1371. for a,b in ea{
  1372. if(ea[a]!=cea[a]&&a~="\b(x|y|w|h)")
  1373. move.=a b " "
  1374. ctrl.SetAttribute(a,b)
  1375. }
  1376. if move
  1377. GuiControl,3:MoveDraw,% ea.hwnd,%move%
  1378. }
  1379. highlight(),DisplaySelected()
  1380. SetTimer,Redraw,-10
  1381. }
  1382. }
  1383. Redo(){
  1384. undo.redogo()
  1385. }
  1386. Testing(){
  1387.  
  1388. }
  1389. WinPos(x:="",y:=""){
  1390. ControlGetPos,xx,yy,ww,hh,,% hwnd([3])
  1391. VarSetCapacity(rect,16),DllCall("GetClientRect",ptr,hwnd(3),ptr,&rect),x-=xx+v.Border,y-=yy+v.Border+v.Caption,w:=NumGet(rect,8,"int"),h:=NumGet(rect,12,"int")
  1392. return {x:x,y:y,w:w,h:h}
  1393. }
  1394. CompileItem(node){
  1395. ea:=xml.ea(node),index:=0
  1396. item:="Gui,Add," ea.type ","
  1397. for a,b in StrSplit("x,y,w,h,g,v",",")
  1398. if(ea[b]!="")
  1399. item.=(index=0?"":" ") b ea[b],index++
  1400. if(ea.option)
  1401. item.=" " ea.option
  1402. item.="," ea.value
  1403. return item
  1404. }
  1405. f1::
  1406. file:=window.ssn("//filename").text
  1407. ;SplitPath,file,,dir
  1408. Run,%file%
  1409. return
  1410. TabNotify(){
  1411. v.tabbutton:=1
  1412. }
  1413. Escape(){
  1414. all:=window.sn("//*[@selected]")
  1415. while,aa:=all.item[A_Index-1]
  1416. aa.RemoveAttribute("selected")
  1417. Highlight()
  1418. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement