Subversion Repositories Kolibri OS

Rev

Rev 9645 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. (*
  2.     Copyright 2016, 2018, 2020-2023 Anton Krotov
  3.  
  4.     This program is free software: you can redistribute it and/or modify
  5.     it under the terms of the GNU Lesser General Public License as published by
  6.     the Free Software Foundation, either version 3 of the License, or
  7.     (at your option) any later version.
  8.  
  9.     This program is distributed in the hope that it will be useful,
  10.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12.     GNU Lesser General Public License for more details.
  13.  
  14.     You should have received a copy of the GNU Lesser General Public License
  15.     along with this program.  If not, see <http://www.gnu.org/licenses/>.
  16. *)
  17.  
  18. MODULE OpenDlg;
  19.  
  20. IMPORT sys := SYSTEM;
  21.  
  22. CONST
  23.   topen* = 0;
  24.   tsave* = 1;
  25.   tdir* = 2;
  26.  
  27.   libName = "proc_lib.obj";
  28.  
  29. TYPE
  30.  
  31.   DRAW_WINDOW = PROCEDURE;
  32.  
  33.   tFilterArea = POINTER TO RECORD
  34.       size: INTEGER;
  35.       filter: ARRAY 4096 OF CHAR
  36.   END;
  37.  
  38.   TDialog = RECORD
  39.     _type*,
  40.     procinfo,
  41.     com_area_name,
  42.     com_area,
  43.     opendir_path,
  44.     dir_default_path,
  45.     start_path: INTEGER;
  46.     draw_window: DRAW_WINDOW;
  47.     status*,
  48.     openfile_path,
  49.     filename_area: INTEGER;
  50.     filter_area: tFilterArea;
  51.     X, Y: INTEGER;
  52.     procinf: ARRAY 1024 OF CHAR;
  53.     s_com_area_name: ARRAY 32 OF CHAR;
  54.     s_opendir_path,
  55.     s_dir_default_path,
  56.     FilePath*,
  57.     FileName*: ARRAY 4096 OF CHAR
  58.   END;
  59.  
  60.   Dialog* = POINTER TO TDialog;
  61.  
  62. VAR
  63.  
  64.   filter_area: tFilterArea;
  65.  
  66.  
  67. PROCEDURE [stdcall, libName, ""] OpenDialog_init (od: Dialog); END;
  68. PROCEDURE [stdcall, libName, ""] OpenDialog_start (od: Dialog); END;
  69.  
  70. PROCEDURE Show*(od: Dialog; Width, Height: INTEGER);
  71. BEGIN
  72.   IF od # NIL THEN
  73.     od.X := Width;
  74.     od.Y := Height;
  75.     OpenDialog_start(od)
  76.   END
  77. END Show;
  78.  
  79.  
  80. PROCEDURE replace (VAR str: ARRAY OF CHAR; c1, c2: CHAR);
  81. VAR
  82.     i: INTEGER;
  83. BEGIN
  84.     i := LENGTH(str) - 1;
  85.     WHILE i >= 0 DO
  86.         IF str[i] = c1 THEN
  87.             str[i] := c2
  88.         END;
  89.         DEC(i)
  90.     END
  91. END replace;
  92.  
  93.  
  94. PROCEDURE SetFilter* (dlg: Dialog; filter: ARRAY OF CHAR);
  95. VAR
  96.     n, i: INTEGER;
  97. BEGIN
  98.     IF filter = "" THEN
  99.         dlg.filter_area := NIL
  100.     ELSE
  101.         dlg.filter_area := filter_area;
  102.         filter_area.filter := filter;
  103.         n := LENGTH(filter_area.filter);
  104.         FOR i := 0 TO 3 DO
  105.             filter_area.filter[n + i] := "|"
  106.         END;
  107.         filter_area.filter[n + 4] := 0X;
  108.         filter_area.size := LENGTH(filter_area.filter);
  109.         replace(filter_area.filter, "|", 0X)
  110.     END
  111. END SetFilter;
  112.  
  113.  
  114. PROCEDURE Create*(draw_window: DRAW_WINDOW; _type: INTEGER; def_path, filter: ARRAY OF CHAR): Dialog;
  115. VAR res: Dialog;
  116. BEGIN
  117.   NEW(res);
  118.   IF res # NIL THEN
  119.     NEW(filter_area);
  120.     IF filter_area # NIL THEN
  121.       res.filter_area := filter_area;
  122.       res.s_com_area_name    := "FFFFFFFF_open_dialog";
  123.       res.com_area           := 0;
  124.       res._type              := _type;
  125.       res.draw_window        := draw_window;
  126.       COPY(def_path, res.s_dir_default_path);
  127.       SetFilter(res, filter);
  128.       res.X                  := 0;
  129.       res.Y                  := 0;
  130.       res.s_opendir_path     := res.s_dir_default_path;
  131.       res.FilePath           := "";
  132.       res.FileName           := "";
  133.       res.status             := 0;
  134.       res.procinfo           := sys.ADR(res.procinf[0]);
  135.       res.com_area_name      := sys.ADR(res.s_com_area_name[0]);
  136.       res.start_path         := sys.SADR("/sys/File managers/opendial");
  137.       res.opendir_path       := sys.ADR(res.s_opendir_path[0]);
  138.       res.dir_default_path   := sys.ADR(res.s_dir_default_path[0]);
  139.       res.openfile_path      := sys.ADR(res.FilePath[0]);
  140.       res.filename_area      := sys.ADR(res.FileName[0]);
  141.       OpenDialog_init(res)
  142.     ELSE
  143.       DISPOSE(res)
  144.     END
  145.   END
  146.   RETURN res
  147. END Create;
  148.  
  149. PROCEDURE Destroy*(VAR od: Dialog);
  150. BEGIN
  151.   IF od # NIL THEN
  152.     DISPOSE(od.filter_area);
  153.     DISPOSE(od)
  154.   END
  155. END Destroy;
  156.  
  157.  
  158. END OpenDlg.