titlebar.m 2.4 KB

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