Window IO.h 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. /******************************************************************************/
  2. enum WIN_IO_MODE : Byte // WindowIO mode
  3. {
  4. WIN_IO_LOAD, // load file
  5. WIN_IO_SAVE, // save file
  6. WIN_IO_DIR , // directory select
  7. };
  8. enum WIN_IO_PATH_MODE : Byte // WindowIO title bar path display mode
  9. {
  10. WIN_IO_PM_NONE, // none , path will not be included in the title bar
  11. WIN_IO_PM_PART, // partly, only sub-path will be included in the title bar
  12. WIN_IO_PM_FULL, // fully , full path and sub-path will be included in the title bar
  13. };
  14. enum WIN_IO_EXT_MODE : Byte // WindowIO extension append mode
  15. {
  16. WIN_IO_EXT_NEVER , // never append extension
  17. WIN_IO_EXT_EMPTY , // append extension only when not specified
  18. WIN_IO_EXT_ALWAYS, // always append extension
  19. };
  20. /******************************************************************************/
  21. const_mem_addr STRUCT(QuickPathSelector , ComboBox)
  22. //{
  23. ComboBox& create();
  24. ComboBox& create(C Rect &rect) {return create().rect(rect);} // create and set rectangle
  25. virtual Str getPath( ) {return S;} // get current path, extend this function to return current path in your custom file browser
  26. virtual void setPath(C Str &path) { } // set current path, extend this function to set current path in your custom file browser
  27. #if EE_PRIVATE
  28. void setData(); // call this to update path selector paths from the global variables
  29. #endif
  30. #if !EE_PRIVATE
  31. private:
  32. #endif
  33. void (*_func)(Ptr user);
  34. };
  35. /******************************************************************************/
  36. const_mem_addr STRUCT(WindowIO , ClosableWindow) // Gui Window Input Output !! must be stored in constant memory address !!
  37. //{
  38. WIN_IO_PATH_MODE path_mode; // path display mode, default=WIN_IO_PM_FULL
  39. WIN_IO_EXT_MODE ext_mode; // extension append mode, default=WIN_IO_EXT_ALWAYS
  40. Button ok , // ok
  41. cancel , // cancel
  42. create_dir, // create directory
  43. up , // up folder
  44. rename , // rename
  45. remove , // delete
  46. explore ; // explore
  47. TextLine textline ; // text line
  48. Region region ; // region
  49. Window rename_window ; // rename window
  50. TextLine rename_textline; // rename text line
  51. Window remove_window; // delete window
  52. Text remove_text ; // delete text
  53. Button remove_yes , // delete yes
  54. remove_no ; // delete no
  55. Window overwrite_window; // overwrite window
  56. Text overwrite_text ; // overwrite text
  57. Button overwrite_yes , // overwrite yes
  58. overwrite_no ; // overwrite no
  59. // manage
  60. WindowIO& del ( ); // delete
  61. WindowIO& create(C Str &ext=S, C Str &path=S, C Str &sub_path=S, void (*load)(C Str &name, Ptr user)=null, void (*save)(C Str &name, Ptr user)=null, Ptr user=null); // create
  62. T1(TYPE) WindowIO& create(C Str &ext , C Str &path , C Str &sub_path , void (*load)(C Str &name, TYPE *user) , void (*save)(C Str &name, TYPE *user) , TYPE *user ) {return create(ext, path, sub_path).io(load, save, user);}
  63. T1(TYPE) WindowIO& create(C Str &ext , C Str &path , C Str &sub_path , void (*load)(C Str &name, TYPE &user) , void (*save)(C Str &name, TYPE &user) , TYPE &user ) {return create(ext, path, sub_path).io(load, save, user);}
  64. // set / get
  65. WindowIO& ext (C Str &ext , C Str &desc =S); C Str& ext ()C {return _ext;} // set/get supported extensions, 'ext'=list of supported extensions separated with '|' symbol (null for all kinds of extensions), 'desc'=description of supported files types (if specified then it will be used in the window title bar instead of the 1st extension)
  66. WindowIO& path(C Str &path, C Str &sub_path=S); C Str& path ()C {return _path;} // set/get io path's, 'path'=main path, 'sub_path'=sub-path
  67. C Str& subPath()C {return _sub_path;} // get sub-path
  68. WindowIO& name(C Str &name ); // set default file name, this is equal to setting the textline value to 'name'
  69. WindowIO& modeDirSelect ( ); // set a special mode which is used for directory selection
  70. WindowIO& modeDirOperate( ); // set a special mode which is used for saving/loading directories with a specified extension (instead of files), in order to activate this mode - extension must be set
  71. WindowIO& level (Int level ); // set window levels
  72. WindowIO& io (void (*load)(C Str &name, Ptr user)=null, void (*save)(C Str &name, Ptr user)=null, Ptr user=null); // set io functions
  73. T1(TYPE) WindowIO& io (void (*load)(C Str &name, TYPE *user) , void (*save)(C Str &name, TYPE *user) , TYPE *user ) {return io((void(*)(C Str&, Ptr))load, (void(*)(C Str&, Ptr))save, user);}
  74. T1(TYPE) WindowIO& io (void (*load)(C Str &name, TYPE &user) , void (*save)(C Str &name, TYPE &user) , TYPE &user ) {return io((void(*)(C Str&, Ptr))load, (void(*)(C Str&, Ptr))save, &user);}
  75. // operations
  76. virtual WindowIO& hide (); // hide
  77. virtual WindowIO& show (); // show
  78. virtual WindowIO& activate(); // activate
  79. virtual WindowIO& save (); // activate to save
  80. virtual WindowIO& load (); // activate to load
  81. #if EE_PRIVATE
  82. void zero ( );
  83. void setBar ( );
  84. void setRect ( );
  85. void getList ( );
  86. void setFile (C Str &name);
  87. void back ( );
  88. void enter (C Str &dir );
  89. Str final (C Str &name)C;
  90. Str final ( )C;
  91. void Ok ( );
  92. void createDir ( );
  93. void renameDo ( );
  94. void removeAsk ( );
  95. void removeDo ( );
  96. void removeCancel ( );
  97. Bool overwriteAsk (C Str &name);
  98. void overwriteDo ( );
  99. void overwriteCancel( );
  100. void exploreDo ( );
  101. Bool goodExt (C Str &name)C;
  102. WindowIO& fullScreen( ); // set full screen mode
  103. #endif
  104. virtual Rect sizeLimit( )C; // set allowed size limits for the Window rectangle, you can override this method and return custom values, they will be used by 'rect' method
  105. virtual WindowIO& rect (C Rect &rect) ; C Rect& rect()C {return super::rect();} // set/get rectangle
  106. virtual void update (C GuiPC &gpc ) ;
  107. ~WindowIO() {del();}
  108. WindowIO();
  109. #if !EE_PRIVATE
  110. private:
  111. #endif
  112. struct File // WindowIO File
  113. {
  114. UInt type; // file type (this is FSTD_TYPE but keep as UInt so 'List.setElmType' which operates on UInt can be used)
  115. Long size; // file size
  116. Str name; // file name
  117. #if EE_PRIVATE
  118. void set(FSTD_TYPE type, Long size, C Str &name) {T.type=type; T.size=size; T.name=name;}
  119. #endif
  120. };
  121. const_mem_addr STRUCT(QPS , QuickPathSelector)
  122. //{
  123. WindowIO &win_io;
  124. virtual Str getPath( );
  125. virtual void setPath(C Str &path);
  126. QPS(WindowIO &win_io);
  127. };
  128. WIN_IO_MODE _mode;
  129. Bool _dir_operate;
  130. Flt _border;
  131. Ptr _func_user;
  132. void (*_load)(C Str &name, Ptr user),
  133. (*_save)(C Str &name, Ptr user);
  134. Str _ext, _ext_desc, _path, _sub_path, _op_name;
  135. Mems<Str > _dot_exts;
  136. Memc<File> file;
  137. List<File> list;
  138. MenuBar menu;
  139. QPS quick;
  140. NO_COPY_CONSTRUCTOR(WindowIO);
  141. };
  142. /******************************************************************************/
  143. extern Memc<Str> WindowIOFavorites, WindowIORecents;
  144. /******************************************************************************/