Subversion Repositories Kolibri OS

Rev

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

  1. (*
  2.     Copyright 2016, 2022, 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. TYPE
  23.  
  24.   DRAW_WINDOW = PROCEDURE;
  25.  
  26.   TDialog = RECORD
  27.     type,
  28.     procinfo,
  29.     com_area_name,
  30.     com_area,
  31.     opendir_path,
  32.     dir_default_path,
  33.     start_path: INTEGER;
  34.     draw_window: DRAW_WINDOW;
  35.     status*,
  36.     openfile_path,
  37.     filename_area: INTEGER;
  38.     filter_area:
  39.       POINTER TO RECORD
  40.         size: INTEGER;
  41.         filter: ARRAY 4096 OF CHAR
  42.       END;
  43.     X, Y: INTEGER;
  44.  
  45.     procinf: ARRAY 1024 OF CHAR;
  46.     s_com_area_name: ARRAY 32 OF CHAR;
  47.     s_opendir_path,
  48.     s_dir_default_path,
  49.     FilePath*,
  50.     FileName*: ARRAY 4096 OF CHAR
  51.   END;
  52.  
  53.   Dialog* = POINTER TO TDialog;
  54.  
  55.  
  56. PROCEDURE [stdcall, "Proc_lib.obj", ""] OpenDialog_start (od: Dialog); END;
  57. PROCEDURE [stdcall, "Proc_lib.obj", ""] OpenDialog_init (od: Dialog); END;
  58.  
  59. PROCEDURE Show*(od: Dialog; Width, Height: INTEGER);
  60. BEGIN
  61.   IF od # NIL THEN
  62.     od.X := Width;
  63.     od.Y := Height;
  64.     OpenDialog_start(od)
  65.   END
  66. END Show;
  67.  
  68. PROCEDURE Create*(draw_window: DRAW_WINDOW; type: INTEGER; def_path, filter: ARRAY OF CHAR): Dialog;
  69. VAR res: Dialog; n, i: INTEGER;
  70.  
  71.   PROCEDURE replace(VAR str: ARRAY OF CHAR; c1, c2: CHAR);
  72.   VAR i: INTEGER;
  73.   BEGIN
  74.     i := LENGTH(str) - 1;
  75.     WHILE i >= 0 DO
  76.       IF str[i] = c1 THEN
  77.         str[i] := c2
  78.       END;
  79.       DEC(i)
  80.     END
  81.   END replace;
  82.  
  83. BEGIN
  84.   NEW(res);
  85.   IF res # NIL THEN
  86.     NEW(res.filter_area);
  87.     IF res.filter_area # NIL THEN
  88.       res.s_com_area_name    := "FFFFFFFF_open_dialog";
  89.       res.com_area           := 0;
  90.       res.type               := type;
  91.       res.draw_window        := draw_window;
  92.       COPY(def_path, res.s_dir_default_path);
  93.       COPY(filter,   res.filter_area.filter);
  94.  
  95.       n := LENGTH(res.filter_area.filter);
  96.       FOR i := 0 TO 3 DO
  97.         res.filter_area.filter[n + i] := "|"
  98.       END;
  99.       res.filter_area.filter[n + 4] := 0X;
  100.  
  101.       res.X                  := 0;
  102.       res.Y                  := 0;
  103.       res.s_opendir_path     := res.s_dir_default_path;
  104.       res.FilePath           := "";
  105.       res.FileName           := "";
  106.       res.status             := 0;
  107.       res.filter_area.size   := LENGTH(res.filter_area.filter);
  108.       res.procinfo           := sys.ADR(res.procinf[0]);
  109.       res.com_area_name      := sys.ADR(res.s_com_area_name[0]);
  110.       res.start_path         := sys.SADR("/sys/File managers/opendial");
  111.       res.opendir_path       := sys.ADR(res.s_opendir_path[0]);
  112.       res.dir_default_path   := sys.ADR(res.s_dir_default_path[0]);
  113.       res.openfile_path      := sys.ADR(res.FilePath[0]);
  114.       res.filename_area      := sys.ADR(res.FileName[0]);
  115.  
  116.       replace(res.filter_area.filter, "|", 0X);
  117.       OpenDialog_init(res)
  118.     ELSE
  119.       DISPOSE(res)
  120.     END
  121.   END
  122.   RETURN res
  123. END Create;
  124.  
  125. PROCEDURE Destroy*(VAR od: Dialog);
  126. BEGIN
  127.   IF od # NIL THEN
  128.     DISPOSE(od.filter_area);
  129.     DISPOSE(od)
  130.   END
  131. END Destroy;
  132.  
  133.  
  134. END OpenDlg.
  135.