You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

476 lines
15KB

  1. //
  2. // "$Id: Fl_File_Chooser.cxx 8786 2011-06-07 11:41:36Z manolo $"
  3. //
  4. // Fl_File_Chooser dialog for the Fast Light Tool Kit (FLTK).
  5. //
  6. // Copyright 1998-2011 by Bill Spitzak and others.
  7. //
  8. // This library is free software; you can redistribute it and/or
  9. // modify it under the terms of the GNU Library General Public
  10. // License as published by the Free Software Foundation; either
  11. // version 2 of the License, or (at your option) any later version.
  12. //
  13. // This library is distributed in the hope that it will be useful,
  14. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. // Library General Public License for more details.
  17. //
  18. // You should have received a copy of the GNU Library General Public
  19. // License along with this library; if not, write to the Free Software
  20. // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
  21. // USA.
  22. //
  23. // Please report all bugs and problems on the following page:
  24. //
  25. // http://www.fltk.org/str.php
  26. //
  27. // generated by Fast Light User Interface Designer (fluid) version 1.0300
  28. #include "../FL/Fl_File_Chooser.H"
  29. #include <FL/fl_draw.H>
  30. void Fl_File_Chooser::cb_window_i(Fl_Double_Window*, void*) {
  31. fileName->value("");
  32. fileList->deselect();
  33. Fl::remove_timeout((Fl_Timeout_Handler)previewCB, this);
  34. window->hide();
  35. }
  36. void Fl_File_Chooser::cb_window(Fl_Double_Window* o, void* v) {
  37. ((Fl_File_Chooser*)(o->user_data()))->cb_window_i(o,v);
  38. }
  39. void Fl_File_Chooser::cb_showChoice_i(Fl_Choice*, void*) {
  40. showChoiceCB();
  41. }
  42. void Fl_File_Chooser::cb_showChoice(Fl_Choice* o, void* v) {
  43. ((Fl_File_Chooser*)(o->parent()->parent()->user_data()))->cb_showChoice_i(o,v);
  44. }
  45. void Fl_File_Chooser::cb_favoritesButton_i(Fl_Menu_Button*, void*) {
  46. favoritesButtonCB();
  47. }
  48. void Fl_File_Chooser::cb_favoritesButton(Fl_Menu_Button* o, void* v) {
  49. ((Fl_File_Chooser*)(o->parent()->parent()->user_data()))->cb_favoritesButton_i(o,v);
  50. }
  51. void Fl_File_Chooser::cb_newButton_i(Fl_Button*, void*) {
  52. newdir();
  53. }
  54. void Fl_File_Chooser::cb_newButton(Fl_Button* o, void* v) {
  55. ((Fl_File_Chooser*)(o->parent()->parent()->user_data()))->cb_newButton_i(o,v);
  56. }
  57. #include <FL/Fl_Bitmap.H>
  58. static unsigned char idata_new[] =
  59. {0,0,120,0,132,0,2,1,1,254,1,128,49,128,49,128,253,128,253,128,49,128,49,
  60. 128,1,128,1,128,255,255,0,0};
  61. static Fl_Bitmap image_new(idata_new, 16, 16);
  62. void Fl_File_Chooser::cb__i(Fl_Tile*, void*) {
  63. update_preview();
  64. }
  65. void Fl_File_Chooser::cb_(Fl_Tile* o, void* v) {
  66. ((Fl_File_Chooser*)(o->parent()->user_data()))->cb__i(o,v);
  67. }
  68. void Fl_File_Chooser::cb_fileList_i(Fl_File_Browser*, void*) {
  69. fileListCB();
  70. }
  71. void Fl_File_Chooser::cb_fileList(Fl_File_Browser* o, void* v) {
  72. ((Fl_File_Chooser*)(o->parent()->parent()->user_data()))->cb_fileList_i(o,v);
  73. }
  74. void Fl_File_Chooser::cb_previewButton_i(Fl_Check_Button*, void*) {
  75. preview(previewButton->value());
  76. }
  77. void Fl_File_Chooser::cb_previewButton(Fl_Check_Button* o, void* v) {
  78. ((Fl_File_Chooser*)(o->parent()->parent()->parent()->user_data()))->cb_previewButton_i(o,v);
  79. }
  80. void Fl_File_Chooser::cb_showHiddenButton_i(Fl_Check_Button*, void*) {
  81. showHidden(showHiddenButton->value());
  82. }
  83. void Fl_File_Chooser::cb_showHiddenButton(Fl_Check_Button* o, void* v) {
  84. ((Fl_File_Chooser*)(o->parent()->parent()->parent()->user_data()))->cb_showHiddenButton_i(o,v);
  85. }
  86. void Fl_File_Chooser::cb_fileName_i(Fl_File_Input*, void*) {
  87. fileNameCB();
  88. }
  89. void Fl_File_Chooser::cb_fileName(Fl_File_Input* o, void* v) {
  90. ((Fl_File_Chooser*)(o->parent()->parent()->user_data()))->cb_fileName_i(o,v);
  91. }
  92. void Fl_File_Chooser::cb_okButton_i(Fl_Return_Button*, void*) {
  93. window->hide();
  94. // Do any callback that is registered...
  95. if (callback_)
  96. (*callback_)(this, data_);
  97. }
  98. void Fl_File_Chooser::cb_okButton(Fl_Return_Button* o, void* v) {
  99. ((Fl_File_Chooser*)(o->parent()->parent()->parent()->user_data()))->cb_okButton_i(o,v);
  100. }
  101. void Fl_File_Chooser::cb_cancelButton_i(Fl_Button*, void*) {
  102. fileName->value("");
  103. fileList->deselect();
  104. Fl::remove_timeout((Fl_Timeout_Handler)previewCB, this);
  105. window->hide();
  106. }
  107. void Fl_File_Chooser::cb_cancelButton(Fl_Button* o, void* v) {
  108. ((Fl_File_Chooser*)(o->parent()->parent()->parent()->user_data()))->cb_cancelButton_i(o,v);
  109. }
  110. void Fl_File_Chooser::cb_favList_i(Fl_File_Browser*, void*) {
  111. favoritesCB(favList);
  112. }
  113. void Fl_File_Chooser::cb_favList(Fl_File_Browser* o, void* v) {
  114. ((Fl_File_Chooser*)(o->parent()->user_data()))->cb_favList_i(o,v);
  115. }
  116. void Fl_File_Chooser::cb_favUpButton_i(Fl_Button*, void*) {
  117. favoritesCB(favUpButton);
  118. }
  119. void Fl_File_Chooser::cb_favUpButton(Fl_Button* o, void* v) {
  120. ((Fl_File_Chooser*)(o->parent()->parent()->user_data()))->cb_favUpButton_i(o,v);
  121. }
  122. void Fl_File_Chooser::cb_favDeleteButton_i(Fl_Button*, void*) {
  123. favoritesCB(favDeleteButton);
  124. }
  125. void Fl_File_Chooser::cb_favDeleteButton(Fl_Button* o, void* v) {
  126. ((Fl_File_Chooser*)(o->parent()->parent()->user_data()))->cb_favDeleteButton_i(o,v);
  127. }
  128. void Fl_File_Chooser::cb_favDownButton_i(Fl_Button*, void*) {
  129. favoritesCB(favDownButton);
  130. }
  131. void Fl_File_Chooser::cb_favDownButton(Fl_Button* o, void* v) {
  132. ((Fl_File_Chooser*)(o->parent()->parent()->user_data()))->cb_favDownButton_i(o,v);
  133. }
  134. void Fl_File_Chooser::cb_favCancelButton_i(Fl_Button*, void*) {
  135. favWindow->hide();
  136. }
  137. void Fl_File_Chooser::cb_favCancelButton(Fl_Button* o, void* v) {
  138. ((Fl_File_Chooser*)(o->parent()->parent()->user_data()))->cb_favCancelButton_i(o,v);
  139. }
  140. void Fl_File_Chooser::cb_favOkButton_i(Fl_Return_Button*, void*) {
  141. favoritesCB(favOkButton);
  142. }
  143. void Fl_File_Chooser::cb_favOkButton(Fl_Return_Button* o, void* v) {
  144. ((Fl_File_Chooser*)(o->parent()->parent()->user_data()))->cb_favOkButton_i(o,v);
  145. }
  146. Fl_File_Chooser::Fl_File_Chooser(const char *d, const char *p, int t, const char *title) {
  147. Fl_Group *prev_current = Fl_Group::current();
  148. { window = new Fl_Double_Window(490, 380, "Choose File");
  149. window->callback((Fl_Callback*)cb_window, (void*)(this));
  150. { Fl_Group* o = new Fl_Group(10, 10, 470, 25);
  151. { showChoice = new Fl_Choice(65, 10, 215, 25, "Show:");
  152. showChoice->down_box(FL_BORDER_BOX);
  153. showChoice->labelfont(1);
  154. showChoice->callback((Fl_Callback*)cb_showChoice);
  155. Fl_Group::current()->resizable(showChoice);
  156. showChoice->label(show_label);
  157. } // Fl_Choice* showChoice
  158. { favoritesButton = new Fl_Menu_Button(290, 10, 155, 25, "Favorites");
  159. favoritesButton->down_box(FL_BORDER_BOX);
  160. favoritesButton->callback((Fl_Callback*)cb_favoritesButton);
  161. favoritesButton->align(Fl_Align(FL_ALIGN_LEFT|FL_ALIGN_INSIDE));
  162. favoritesButton->label(favorites_label);
  163. } // Fl_Menu_Button* favoritesButton
  164. { Fl_Button* o = newButton = new Fl_Button(455, 10, 25, 25);
  165. newButton->image(image_new);
  166. newButton->labelsize(8);
  167. newButton->callback((Fl_Callback*)cb_newButton);
  168. o->tooltip(new_directory_tooltip);
  169. } // Fl_Button* newButton
  170. o->end();
  171. } // Fl_Group* o
  172. { Fl_Tile* o = new Fl_Tile(10, 45, 470, 225);
  173. o->callback((Fl_Callback*)cb_);
  174. { fileList = new Fl_File_Browser(10, 45, 295, 225);
  175. fileList->type(2);
  176. fileList->callback((Fl_Callback*)cb_fileList);
  177. fileList->window()->hotspot(fileList);
  178. } // Fl_File_Browser* fileList
  179. { previewBox = new Fl_Box(305, 45, 175, 225, "?");
  180. previewBox->box(FL_DOWN_BOX);
  181. previewBox->labelsize(100);
  182. previewBox->align(Fl_Align(FL_ALIGN_CLIP|FL_ALIGN_INSIDE));
  183. } // Fl_Box* previewBox
  184. o->end();
  185. Fl_Group::current()->resizable(o);
  186. } // Fl_Tile* o
  187. { Fl_Group* o = new Fl_Group(10, 275, 470, 95);
  188. { Fl_Group* o = new Fl_Group(10, 275, 470, 20);
  189. { previewButton = new Fl_Check_Button(10, 275, 73, 20, "Preview");
  190. previewButton->shortcut(0x80070);
  191. previewButton->down_box(FL_DOWN_BOX);
  192. previewButton->value(1);
  193. previewButton->callback((Fl_Callback*)cb_previewButton);
  194. previewButton->label(preview_label);
  195. } // Fl_Check_Button* previewButton
  196. { showHiddenButton = new Fl_Check_Button(115, 275, 165, 20, "Show hidden files");
  197. showHiddenButton->down_box(FL_DOWN_BOX);
  198. showHiddenButton->callback((Fl_Callback*)cb_showHiddenButton);
  199. showHiddenButton->label(hidden_label);
  200. } // Fl_Check_Button* showHiddenButton
  201. { Fl_Box* o = new Fl_Box(115, 275, 365, 20);
  202. Fl_Group::current()->resizable(o);
  203. } // Fl_Box* o
  204. o->end();
  205. } // Fl_Group* o
  206. { fileName = new Fl_File_Input(115, 300, 365, 35);
  207. fileName->labelfont(1);
  208. fileName->callback((Fl_Callback*)cb_fileName);
  209. fileName->when(FL_WHEN_ENTER_KEY);
  210. Fl_Group::current()->resizable(fileName);
  211. fileName->when(FL_WHEN_CHANGED | FL_WHEN_ENTER_KEY);
  212. } // Fl_File_Input* fileName
  213. { Fl_Box* o = new Fl_Box(10, 310, 105, 25, "Filename:");
  214. o->labelfont(1);
  215. o->align(Fl_Align(FL_ALIGN_RIGHT|FL_ALIGN_INSIDE));
  216. o->label(filename_label);
  217. } // Fl_Box* o
  218. { Fl_Group* o = new Fl_Group(10, 345, 470, 25);
  219. { okButton = new Fl_Return_Button(313, 345, 85, 25, "OK");
  220. okButton->callback((Fl_Callback*)cb_okButton);
  221. okButton->label(fl_ok);
  222. } // Fl_Return_Button* okButton
  223. { Fl_Button* o = cancelButton = new Fl_Button(408, 345, 72, 25, "Cancel");
  224. cancelButton->callback((Fl_Callback*)cb_cancelButton);
  225. o->label(fl_cancel);
  226. } // Fl_Button* cancelButton
  227. { Fl_Box* o = new Fl_Box(10, 345, 30, 25);
  228. Fl_Group::current()->resizable(o);
  229. } // Fl_Box* o
  230. o->end();
  231. } // Fl_Group* o
  232. o->end();
  233. } // Fl_Group* o
  234. if (title) window->label(title);
  235. window->set_modal();
  236. window->end();
  237. } // Fl_Double_Window* window
  238. { favWindow = new Fl_Double_Window(355, 150, "Manage Favorites");
  239. favWindow->user_data((void*)(this));
  240. { favList = new Fl_File_Browser(10, 10, 300, 95);
  241. favList->type(2);
  242. favList->callback((Fl_Callback*)cb_favList);
  243. Fl_Group::current()->resizable(favList);
  244. } // Fl_File_Browser* favList
  245. { Fl_Group* o = new Fl_Group(320, 10, 25, 95);
  246. { favUpButton = new Fl_Button(320, 10, 25, 25, "@8>");
  247. favUpButton->callback((Fl_Callback*)cb_favUpButton);
  248. } // Fl_Button* favUpButton
  249. { favDeleteButton = new Fl_Button(320, 45, 25, 25, "X");
  250. favDeleteButton->labelfont(1);
  251. favDeleteButton->callback((Fl_Callback*)cb_favDeleteButton);
  252. Fl_Group::current()->resizable(favDeleteButton);
  253. } // Fl_Button* favDeleteButton
  254. { favDownButton = new Fl_Button(320, 80, 25, 25, "@2>");
  255. favDownButton->callback((Fl_Callback*)cb_favDownButton);
  256. } // Fl_Button* favDownButton
  257. o->end();
  258. } // Fl_Group* o
  259. { Fl_Group* o = new Fl_Group(10, 113, 335, 29);
  260. { favCancelButton = new Fl_Button(273, 115, 72, 25, "Cancel");
  261. favCancelButton->callback((Fl_Callback*)cb_favCancelButton);
  262. favCancelButton->label(fl_cancel);
  263. } // Fl_Button* favCancelButton
  264. { favOkButton = new Fl_Return_Button(181, 115, 79, 25, "Save");
  265. favOkButton->callback((Fl_Callback*)cb_favOkButton);
  266. favOkButton->label(save_label);
  267. } // Fl_Return_Button* favOkButton
  268. { Fl_Box* o = new Fl_Box(10, 115, 161, 25);
  269. Fl_Group::current()->resizable(o);
  270. } // Fl_Box* o
  271. o->end();
  272. } // Fl_Group* o
  273. favWindow->label(manage_favorites_label);
  274. favWindow->set_modal();
  275. favWindow->size_range(181, 150);
  276. favWindow->end();
  277. } // Fl_Double_Window* favWindow
  278. callback_ = 0;
  279. data_ = 0;
  280. directory_[0] = 0;
  281. window->size_range(window->w(), window->h(), Fl::w(), Fl::h());
  282. type(t);
  283. filter(p);
  284. update_favorites();
  285. value(d);
  286. type(t);
  287. int e;
  288. prefs_.get("preview", e, 1);
  289. preview(e);
  290. Fl_Group::current(prev_current);
  291. ext_group=(Fl_Widget*)0;
  292. }
  293. Fl_File_Chooser::~Fl_File_Chooser() {
  294. Fl::remove_timeout((Fl_Timeout_Handler)previewCB, this);
  295. if(ext_group)window->remove(ext_group);
  296. delete window;
  297. delete favWindow;
  298. }
  299. void Fl_File_Chooser::callback(void (*cb)(Fl_File_Chooser *, void *), void *d ) {
  300. callback_ = cb;
  301. data_ = d;
  302. }
  303. void Fl_File_Chooser::color(Fl_Color c) {
  304. fileList->color(c);
  305. }
  306. Fl_Color Fl_File_Chooser::color() {
  307. return (fileList->color());
  308. }
  309. char * Fl_File_Chooser::directory() {
  310. return directory_;
  311. }
  312. const char * Fl_File_Chooser::filter() {
  313. return (fileList->filter());
  314. }
  315. int Fl_File_Chooser::filter_value() {
  316. return showChoice->value();
  317. }
  318. void Fl_File_Chooser::filter_value(int f) {
  319. showChoice->value(f);
  320. showChoiceCB();
  321. }
  322. void Fl_File_Chooser::hide() {
  323. window->hide();
  324. }
  325. void Fl_File_Chooser::iconsize(uchar s) {
  326. fileList->iconsize(s);
  327. }
  328. uchar Fl_File_Chooser::iconsize() {
  329. return (fileList->iconsize());
  330. }
  331. void Fl_File_Chooser::label(const char *l) {
  332. window->label(l);
  333. }
  334. const char * Fl_File_Chooser::label() {
  335. return (window->label());
  336. }
  337. void Fl_File_Chooser::ok_label(const char *l) {
  338. okButton->label(l);
  339. int w=0, h=0;
  340. okButton->measure_label(w, h);
  341. okButton->resize(cancelButton->x() - 50 - w, cancelButton->y(),
  342. w + 40, 25);
  343. okButton->parent()->init_sizes();
  344. }
  345. const char * Fl_File_Chooser::ok_label() {
  346. return (okButton->label());
  347. }
  348. int Fl_File_Chooser::shown() {
  349. return window->shown();
  350. }
  351. void Fl_File_Chooser::textcolor(Fl_Color c) {
  352. fileList->textcolor(c);
  353. }
  354. Fl_Color Fl_File_Chooser::textcolor() {
  355. return (fileList->textcolor());
  356. }
  357. void Fl_File_Chooser::textfont(Fl_Font f) {
  358. fileList->textfont(f);
  359. }
  360. Fl_Font Fl_File_Chooser::textfont() {
  361. return (fileList->textfont());
  362. }
  363. void Fl_File_Chooser::textsize(Fl_Fontsize s) {
  364. fileList->textsize(s);
  365. }
  366. Fl_Fontsize Fl_File_Chooser::textsize() {
  367. return (fileList->textsize());
  368. }
  369. void Fl_File_Chooser::type(int t) {
  370. type_ = t;
  371. if (t & MULTI)
  372. fileList->type(FL_MULTI_BROWSER);
  373. else
  374. fileList->type(FL_HOLD_BROWSER);
  375. if (t & CREATE)
  376. newButton->activate();
  377. else
  378. newButton->deactivate();
  379. if (t & DIRECTORY)
  380. fileList->filetype(Fl_File_Browser::DIRECTORIES);
  381. else
  382. fileList->filetype(Fl_File_Browser::FILES);
  383. }
  384. int Fl_File_Chooser::type() {
  385. return (type_);
  386. }
  387. void * Fl_File_Chooser::user_data() const {
  388. return (data_);
  389. }
  390. void Fl_File_Chooser::user_data(void *d) {
  391. data_ = d;
  392. }
  393. int Fl_File_Chooser::visible() {
  394. return window->visible();
  395. }
  396. Fl_Widget* Fl_File_Chooser::add_extra(Fl_Widget* gr) {
  397. Fl_Widget* ret=ext_group;
  398. if (gr==ext_group) {
  399. return ret;
  400. }
  401. if (ext_group) {
  402. int sh=ext_group->h()+4;
  403. Fl_Widget* svres=window->resizable();
  404. window->resizable(NULL);
  405. window->size(window->w(),window->h()-sh);
  406. window->remove(ext_group);
  407. ext_group=NULL;
  408. window->resizable(svres);
  409. }
  410. if (gr) {
  411. int nh=window->h()+gr->h()+4;
  412. Fl_Widget* svres=window->resizable();
  413. window->resizable(NULL);
  414. window->size(window->w(),nh);
  415. gr->position(2,okButton->y()+okButton->h()+2);
  416. window->add(gr);
  417. ext_group=gr;
  418. window->resizable(svres);
  419. }
  420. return ret;
  421. }
  422. //
  423. // End of "$Id: Fl_File_Chooser.cxx 8786 2011-06-07 11:41:36Z manolo $".
  424. //