titlebar.m 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. #include <lib/std.mi>
  2. #define MARGIN 0
  3. Function resizeObjects();
  4. Global GuiObject left, right, center;
  5. Global Text tcenter;
  6. Global Layer lcenter;
  7. Global Group sg;
  8. Global int padleft, padright;
  9. System.onScriptLoaded() {
  10. padleft = 0;
  11. padright = 0;
  12. sg = getScriptGroup();
  13. if (sg == NULL) {
  14. messageBox("titlebar.maki can only run within a group", "Error", 0, "");
  15. return;
  16. }
  17. left = sg.findObject(getToken(getParam(), ";", 0));
  18. center = sg.findObject(getToken(getParam(), ";", 1));
  19. if (center != NULL) {
  20. tcenter = center.findObject("window.titlebar.title");
  21. lcenter = center.findObject("window.titlebar.title.overlay");
  22. }
  23. right = sg.findObject(getToken(getParam(), ";", 2));
  24. }
  25. // backward compatibility with prerelease notify trick
  26. sg.onNotify(String cmd, String param, int a, int b) {
  27. String _command = getToken(cmd, ",", 0);
  28. String _param = getToken(cmd, ",", 1);
  29. if (_command == "padtitleright" || _command == "padtitleright")
  30. onSetXuiParam(_command, _param);
  31. }
  32. System.onSetXuiParam(String param, String value) {
  33. if (param == "padtitleright") {
  34. padright = padright + StringToInteger(value);
  35. resizeObjects();
  36. }
  37. if (param == "padtitleleft") {
  38. padleft = padleft + StringToInteger(value);
  39. resizeObjects();
  40. }
  41. }
  42. resizeObjects() {
  43. int text_width = 0;
  44. int layout_width = 0;
  45. int group_width = sg.getWidth();
  46. Layout l = sg.getParentLayout();
  47. layout_width = l.getWidth();
  48. if (center != NULL) {
  49. text_width = center.getAutoWidth();
  50. }
  51. int lx = (layout_width - text_width) / 2;
  52. lx = l.clientToScreenX(lx);
  53. lx = sg.screenToClientX(lx);
  54. lx = lx - sg.getLeft();
  55. if (center != NULL) {
  56. center.setXmlParam("x", IntegerToString(lx));
  57. center.setXmlParam("relatx", "0");
  58. center.setXmlParam("w", IntegerToString(text_width));
  59. center.setXmlParam("relatw", "0");
  60. lcenter.setXmlParam("x", IntegerToString(lx));
  61. lcenter.setXmlParam("relatx", "0");
  62. lcenter.setXmlParam("w", IntegerToString(text_width));
  63. lcenter.setXmlParam("relatw", "0");
  64. }
  65. if (left != NULL) {
  66. left.setXmlParam("x", IntegerToString(padleft));
  67. left.setXmlParam("relatx", "0");
  68. left.setXmlParam("w", IntegerToString(lx-padleft-MARGIN));
  69. left.setXmlParam("relatw", "0");
  70. }
  71. if (right != NULL) {
  72. right.setXmlParam("x", IntegerToString(lx+text_width+MARGIN+1));
  73. right.setXmlParam("relatx", "0");
  74. right.setXmlParam("w", "-" + IntegerToString(lx+text_width+1+padright+MARGIN+1)); //IntegerToString(group_width-(lx+text_width)));
  75. right.setXmlParam("relatw", "1");
  76. }
  77. }
  78. tcenter.onTextChanged(string newtext) {
  79. resizeObjects();
  80. }
  81. sg.onResize(int x, int y, int w, int h) {
  82. resizeObjects();
  83. }