PageRenderTime 33ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/nPad/nPad.ahk

http://eucaly61-ahk.googlecode.com/
AutoHotKey | 531 lines | 382 code | 90 blank | 59 comment | 36 complexity | f03f5e5392ac369207c07bd4bbaf3731 MD5 | raw file
  1. ; nPad - Toolbar interface to Lexikos' WindowPad
  2. ; this is still a cooking version, welcome for comments ...
  3. ; http://www.autohotkey.com/forum/topic21703.html
  4. ; WindowPad - multi-monitor window-moving tool
  5. ; http://www.autohotkey.com/forum/topic44249.html
  6. ; transparent GUI over notepad
  7. ; http://www.autohotkey.com/forum/topic30300.html
  8. ; Add ToolTips to controls.
  9. ; ---- Known Issue ----
  10. ; GatherWindows : is it possible to Gather certain process, e.g. EmEditor and it's child window ...
  11. ; tollbar Z-order for window that partially covered by some window
  12. ; => noActive or NA if possible overlap with some other window
  13. ; sometimes will not dock to un-activate window under
  14. ; ---- On Going ----
  15. ; problem to Dock on Always-on-top window ... (get flicker ...)
  16. ; => looks OK so far
  17. ; detect the better location on title bar to dock by WM_NCHITTEST http://www.autohotkey.com/forum/topic22178.html
  18. ; Exclude list, more efficiently exclude tool menu and so on...
  19. ; need find how to exclude QtTabBar right-click context menu
  20. ; => looks OK seems those window will not have title bar property with WM_NCHITTEST
  21. ; how to exclude Desktop (ahk_class Progman) ?
  22. ; => looks OK so far, especially with WM_NCHITTEST
  23. ; (OK) disable docking, click tray icon to wake again
  24. ; ---- To Do ----
  25. ; conditionally disable some buttons based on window status
  26. ; do not resize un-resizeable window
  27. ; do not move un-moveable window
  28. ; if need implement "SetParent" or so ... http://www.autohotkey.com/forum/topic23240.html
  29. ; INI setting
  30. ; adjest pad boundry, e.g. 40/60 or 30/70 ..., but what's the proper user interface for this?
  31. ; Record Window position history for undo (maybe up to 10 or 20 records)
  32. ; more customized button
  33. #SingleInstance, Force
  34. #NoEnv
  35. SetBatchLines, -1
  36. SetTitleMatchMode, 2
  37. CoordMode, Mouse, Screen
  38. #include,nPad-init.ahk
  39. #include,nPad-func.ahk
  40. Goto, Main
  41. gWindowPad:
  42. #include,windowPad.ahk
  43. return
  44. main:
  45. GoSub, gWindowPad
  46. GuiToolBar=1
  47. GuiPadMenu=20
  48. GuiDebug=50
  49. ;Gui, 1:Default
  50. Gui, %GuiToolBar%:Default
  51. Gui, Font, Bold cFFFFFF
  52. GUI, -SysMenu -Border +ToolWindow -Caption
  53. GUI, margin, -1, -1
  54. ; GUI, Color, EEAA99, 0000FF
  55. Menu, Tray, NoStandard
  56. Menu, Tray, Add, Dock On, TrayClick
  57. Menu, Tray, Add,
  58. Menu, Tray, Standard
  59. Menu, Tray, Default, Dock On
  60. Menu, Tray, Click, 1
  61. w_min=
  62. nextX=0
  63. nextY=0
  64. Loop, Parse, btnOrder, `,, %A_Space%`t
  65. {
  66. btnIdx := A_LoopField
  67. Label := lookupByIndex(btnIdx,"btn","Label")
  68. VarName := lookupByIndex(btnIdx,"btn","VarName")
  69. SubName := lookupByIndex(btnIdx,"btn","SubName")
  70. Option := lookupByIndex(btnIdx,"btn","Option")
  71. Hint := lookupByIndex(btnIdx,"btn","Hint")
  72. GuiOption =
  73. GuiOption .= " hwnd" . VarName ; for Tooptip
  74. ifInstring,Option,Disabled
  75. GuiOption .= " Disabled"
  76. GuiOption .= " x" . nextX . " y" . nextY
  77. if VarName
  78. GuiOption .= " v" . VarName
  79. if SubName
  80. GuiOption .= " g" . SubName
  81. GUI, add, button, %GuiOption%, %Label%
  82. AddTooltip(%VarName%,Hint)
  83. GuiControlGet, thisBtn, Pos, %VarName%
  84. if (!w_min)
  85. w_min := thisBtnH
  86. if (thisBtnW < w_min)
  87. {
  88. GuiControl, Move, %VarName%, w%w_min%
  89. GuiControlGet, thisBtn, Pos, %VarName%
  90. }
  91. nextX := thisBtnX + thisBtnW - 1
  92. }
  93. GuiControlGet, lastBtn, Pos, %VarName%
  94. ToolBarW := lastBtnX + lastBtnW
  95. ToolBarH := lastBtnY + lastBtnH
  96. GUI, Show, w%ToolBarW% h%ToolBarH% NoActive
  97. Gui, +LastFound
  98. ToolBar_ID := WinExist()
  99. ;winset, transcolor, EEAA99
  100. HideToolBar()
  101. btnBusy=
  102. ; ---- for debug only ----
  103. Gui, %GuiDebug%:Default
  104. Gui, Font, S11 CDefault
  105. Gui, Add, CheckBox, w200 h20 vifSpyOn gClickSpyOnOff Checked
  106. Gui, Add, CheckBox, xP+250 yP h20 vifAutoPath, Get Path (Alt-V T A)
  107. Gui, Add, Edit, xP-250 yp+30 w400 h300 vSpyInfo, no Data yet ...
  108. Gui, Show, , %applicationName% %applicationVer%
  109. Gui, +LastFound
  110. Debug_ID := WinExist()
  111. Gui, %GuiToolBar%:Default
  112. GoSub ClickSpyOnOff
  113. isDebug=1
  114. ; isDebug=0
  115. SetTimer, GetSpyInfo, 250
  116. ; ---- debug session end ----
  117. DockToID =
  118. goSub gCfg
  119. ; start timer, this is for debug only, normal timer is remaked as the line below
  120. ;SetTimer, KeepDockToolBar, 200
  121. return
  122. gClose:
  123. SetTimer, KeepDockToolBar, Off
  124. HideToolBar()
  125. return
  126. Close:
  127. ExitApp
  128. TrayClick:
  129. isDebug=1
  130. gCfg:
  131. ; ---- for debug only ----
  132. if (!isDebug) {
  133. isDebug=1
  134. GuiControl,,bCfg,!!
  135. AddTooltip(bCfg,"Debug On (Refresh 5 sec)")
  136. SetTimer, KeepDockToolBar, 5000
  137. } else {
  138. isDebug=0
  139. GuiControl,,bCfg,O
  140. AddTooltip(bCfg,"Debug Off")
  141. SetTimer, KeepDockToolBar, 200
  142. }
  143. ; ---- debug session end ----
  144. return
  145. gMaxCross:
  146. btnBusy=1
  147. ;HideToolBar()
  148. this_id := DockTo_ID
  149. SysGet, m, MonitorCount
  150. ; Iterate through all monitors.
  151. Loop, %m%
  152. { ; Check if the window is on this monitor.
  153. SysGet, Mon, Monitor, %A_Index%
  154. if (A_index=1) {
  155. xx1 := MonLeft
  156. xx2 := MonRight
  157. yy1 := MonTop
  158. yy2 := MonBottom
  159. continue
  160. }
  161. xx1 := Math_min(xx1,MonLeft)
  162. xx2 := Math_max(xx2,MonRight)
  163. yy1 := Math_max(yy1,MonTop)
  164. yy2 := Math_min(yy2,MonBottom)
  165. }
  166. this_w := xx2-xx1
  167. this_h := yy2-yy1
  168. WinMove, ahk_id %this_id%,,xx1,yy1,this_w,this_h
  169. ; WinActivate, ahk_id %this_id%
  170. btnBusy=
  171. return
  172. gMov:
  173. btnBusy=1
  174. ;HideToolBar()
  175. this_id := DockTo_ID
  176. WindowScreenMove("Next,ahk_id " . this_id)
  177. ; WinActivate, ahk_id %this_id%
  178. btnBusy=
  179. return
  180. gMovMax:
  181. btnBusy=1
  182. ;HideToolBar()
  183. this_id := DockTo_ID
  184. WindowScreenMove("Next,ahk_id " . this_id)
  185. WinMaximize, ahk_id %this_id%
  186. ; WinActivate, ahk_id %this_id%
  187. btnBusy=
  188. return
  189. gGatP:
  190. btnBusy=1
  191. this_id := DockTo_ID
  192. WinActivate, ahk_id %this_id%
  193. WinWaitActive, ahk_id %this_id%
  194. GatherWindows("A")
  195. WinActivate, ahk_id %this_id%
  196. btnBusy=
  197. return
  198. gGatM:
  199. btnBusy=1
  200. GatherWindows("M")
  201. btnBusy=
  202. return
  203. gGoPad:
  204. GuiControlGet, mainBtn, Pos, %A_GuiControl%
  205. this_id := DockTo_ID
  206. ShowPadMenu(ToolBarX+mainBtnX,ToolBarY+mainBtnY+mainBtnH)
  207. return
  208. gSetPad:
  209. gRecPad:
  210. gMore:
  211. this_id := DockTo_ID
  212. WinActivate, ahk_id %this_id%
  213. Return
  214. gSelectPad:
  215. btnBusy=1
  216. p1 := RegExMatch(A_GuiControl, "PadBtn\K(?P<label>\d+)", this_)
  217. if (this_label) {
  218. ; action := padAction%this_Label%
  219. ; this_param := substr(padAction%this_Label%,strLen("WindowPadMove, "))
  220. p2 := RegExMatch(padAction%this_Label%, "(WindowPadMove,)\K(?P<param>.*)",this_)
  221. WindowPadMove(this_param ",ahk_id " . this_id)
  222. }
  223. btnBusy=
  224. return
  225. HideToolBar()
  226. {
  227. local isVisible
  228. GuiControlGet, isVisible, Visible, %VarName%
  229. if (isVisible) {
  230. GUI, -AlwaysOnTop
  231. GUI, Show, x10000 y0 NA
  232. Gui, Cancel
  233. }
  234. }
  235. KeepDockToolBar:
  236. if btnBusy
  237. return
  238. if PadMenu_ID
  239. ifWinNotActive, ahk_id %PadMenu_ID%
  240. {
  241. Gui,%GuiPadMenu%:Default
  242. Gui,Cancel
  243. Gui,%GuiToolBar%:Default
  244. PadMenu_ID=
  245. }
  246. CoordMode, Mouse, Screen
  247. MouseGetPos, MouseX ,MouseY , win_id, ctrl_id
  248. winGetclass, class2, ahk_id %win_id%
  249. if (!Win_ID)
  250. {
  251. HideToolBar()
  252. return
  253. }
  254. if (win_id=ToolBar_ID) OR (win_id=PadMenu_ID) {
  255. GUI, +AlwaysOnTop
  256. return
  257. }
  258. WinGetPos, ToolBarX, ToolBarY, ToolBarW, ToolBarH, ahk_id %ToolBar_ID%
  259. SurveyDockPos("DockWin_",x2,y1,"ahk_id " . win_ID)
  260. if !x2
  261. {
  262. HideToolBar()
  263. return
  264. }
  265. oldwin_id := DockTo_ID
  266. DockTo_ID := win_id
  267. x1 := x2 - ToolBarW
  268. y2 := y1 + ToolBarH
  269. if (DockWin_ExStyle & 0x8) ; 0x8 is WS_EX_TOPMOST.
  270. {
  271. GUI, +AlwaysOnTop
  272. if (x1<>ToolBarX) OR (y1<>ToolBarY) {
  273. ToolBarX := x1
  274. ToolBarY := y1
  275. GUI, Show, x%ToolBarX% y%ToolBarY% NA
  276. }
  277. return
  278. }
  279. ifWinActive, ahk_id %DockTo_ID%
  280. {
  281. GUI, +AlwaysOnTop
  282. if (x1<>ToolBarX) OR (y1<>ToolBarY) {
  283. ToolBarX := x1
  284. ToolBarY := y1
  285. GUI, Show, x%ToolBarX% y%ToolBarY% NA
  286. }
  287. return
  288. }
  289. SafeOnTop = 1
  290. dd:=1
  291. ; win2 := DllCall( "WindowFromPoint", Int,x1-dd , Int,y1-dd )
  292. win1 := DllCall( "WindowFromPoint", Int,x2+dd , Int,y1-dd )
  293. ; win3 := DllCall( "WindowFromPoint", Int,x2+dd , Int,y2+dd )
  294. ; win4 := DllCall( "WindowFromPoint", Int,x1-dd , Int,y2+dd )
  295. Loop,1
  296. {
  297. if (win%A_Index% <> DockTo_ID)
  298. SafeOnTop =
  299. }
  300. if !SafeOnTop
  301. {
  302. DockTo_ID := oldwin_id
  303. HideToolBar()
  304. return
  305. }
  306. GUI, -AlwaysOnTop
  307. if (x1<>ToolBarX) OR (y1<>ToolBarY) {
  308. ToolBarX := x1
  309. ToolBarY := y1
  310. GUI, Show, x%ToolBarX% y%ToolBarY% NA
  311. return
  312. }
  313. return
  314. ShowPadMenu(xx,yy)
  315. {
  316. local x1, y1, btnIdx, Label, Hint, VarName
  317. Gui, %GuiPadMenu%:Default
  318. Gui, Destroy
  319. Gui, Font, Bold
  320. GUI, -SysMenu -Border +ToolWindow -Caption
  321. GUI, margin, -1, -1
  322. x1=0
  323. y1=0
  324. Loop, Parse, padOrder, `,, %A_Space%`t
  325. {
  326. btnIdx := A_LoopField
  327. Label := lookupByIndex(btnIdx,"pad","Label")
  328. Hint := lookupByIndex(btnIdx,"pad","Hint")
  329. VarName := "PadBtn" . Label
  330. GuiOption := " x" . x1 . " y" . y1 . " w29 h29 ggSelectPad"
  331. GuiOption .= " v" . varName
  332. GuiOption .= " hwnd" . VarName
  333. GUI, add, button, %GuiOption%, %Label%
  334. AddTooltip(%VarName%,Hint)
  335. if mod(A_index,3)=0
  336. {
  337. x1 = 0
  338. y1 += 30
  339. } else
  340. x1 += 30
  341. }
  342. Gui, Show, x%xx% y%yy%
  343. Gui, +LastFound
  344. PadMenu_ID := WinExist()
  345. Gui, %GuiToolBar%:Default
  346. return
  347. }
  348. SurveyDockPos(Result, ByRef x, ByRef y, win_id)
  349. {
  350. local eX, eY, eW, eH, x2, y2, dx, x0, x1, ExStyle
  351. WinGetPos, eX, eY, eW, eH, %win_id%
  352. WinGet, ExStyle, ExStyle, %win_ID%
  353. dx := 5
  354. x2 := eX + eW - dx
  355. y2 := eY + 15
  356. %Result%ifResize=
  357. %Result%ifMinimize=
  358. %Result%ifClose=
  359. %Result%haveTitle=
  360. %Result%ExStyle := ExStyle
  361. x0 =
  362. x1 =
  363. Loop
  364. {
  365. SendMessage, 0x84,, ( y2 << 16 )|x2,, %win_id%
  366. WM_NCHITTEST_Result =%ErrorLevel%
  367. if WM_NCHITTEST_Result = 2
  368. %Result%haveTitle:=1
  369. else {
  370. x0 =
  371. if WM_NCHITTEST_Result = 8
  372. %Result%ifMinimize:=1
  373. else if WM_NCHITTEST_Result = 9
  374. %Result%ifResize:=1
  375. else if WM_NCHITTEST_Result = 20
  376. %Result%ifClose:=1
  377. }
  378. if (%Result%haveTitle)
  379. {
  380. if !x0
  381. x0 := x2
  382. if (x0) {
  383. x1 := x2
  384. if (x0-x1)>100
  385. break
  386. }
  387. }
  388. x2 -= dx
  389. if x2 <= %eX%
  390. break
  391. }
  392. if (x1) {
  393. x := x0-5
  394. y := eY+5
  395. } else {
  396. x=
  397. y=
  398. }
  399. return
  400. }
  401. ; ---- for debug only ----
  402. GetSpyInfo:
  403. GetSpyInfo()
  404. return
  405. GetSpyInfo()
  406. {
  407. local lines, MouseX, MouseY, win_ID, win_title, p_name, class, ctrl_id
  408. Lines =
  409. Lines .= "=> " Win_ID+0 . "`n"
  410. win_id := DockTo_ID
  411. WinGetTitle, win_title, ahk_id %win_id%
  412. WinGet, p_name, ProcessName, ahk_id %win_id%
  413. ;ControlGetText, ctrl_text, %ctrl_id%, ahk_id %win_id%
  414. winGetclass, class, ahk_id %win_id%
  415. Lines .= "[Window] " . win_title "`n[Process] " . p_name . "`n[Control] " ctrl_id . "`n"
  416. Lines .= "[Class] " . class . " / " class2 "`n"
  417. Lines .= "WM_NCHITTEST = " . WM_NCHITTEST_Result . "`n"
  418. ; Lines .= "PATH = '" . currentpath . "'`n"
  419. ; Lines .= "========== [Text] ==========`n" . ctrl_text
  420. Gui, %GuiDebug%:Default
  421. GuiControl,, SpyInfo, %Lines%
  422. Gui, %GuiToolBar%:Default
  423. Return
  424. }
  425. ClickSpyOnOff:
  426. Gui, %GuiDebug%:Default
  427. Gui, Submit, NoHide
  428. if ifSpyOn
  429. {
  430. Gui, +AlwaysOnTop
  431. GuiControl, Text, ifSpyOn, Spy ON (Always on Top)
  432. }
  433. else
  434. {
  435. Gui, -AlwaysOnTop
  436. GuiControl, Text, ifSpyOn, Spy off
  437. }
  438. GuiControl, Focus, SpyInfo
  439. Gui, %GuiToolBar%:Default
  440. return
  441. ; ---- debug session end ----