[80] | 1 | /********************************************************************** <BR>
|
---|
| 2 | This file is part of Crack dot Com's free source code release of
|
---|
| 3 | Golgotha. <a href="http://www.crack.com/golgotha_release"> <BR> for
|
---|
| 4 | information about compiling & licensing issues visit this URL</a>
|
---|
| 5 | <PRE> If that doesn't help, contact Jonathan Clark at
|
---|
| 6 | golgotha_source@usa.net (Subject should have "GOLG" in it)
|
---|
| 7 | ***********************************************************************/
|
---|
| 8 |
|
---|
| 9 | #include "file/get_filename.hh"
|
---|
| 10 | #include "window/style.hh"
|
---|
| 11 | #include "window/window.hh"
|
---|
| 12 | #include "string/string.hh"
|
---|
| 13 | #include "device/device.hh"
|
---|
| 14 | #include "device/kernel.hh"
|
---|
| 15 | #include "string/string.hh"
|
---|
| 16 | #include "gui/text_input.hh"
|
---|
| 17 | #include "window/colorwin.hh"
|
---|
| 18 | #include "gui/create_dialog.hh"
|
---|
| 19 | #include <unistd.h>
|
---|
| 20 |
|
---|
| 21 | class open_string : public i4_str
|
---|
| 22 | {
|
---|
| 23 | public:
|
---|
| 24 | open_string(char *fname)
|
---|
| 25 | : i4_str(strlen(fname))
|
---|
| 26 | {
|
---|
| 27 | len=strlen(fname);
|
---|
| 28 | memcpy(ptr, fname, len);
|
---|
| 29 |
|
---|
| 30 | }
|
---|
| 31 | };
|
---|
| 32 |
|
---|
| 33 |
|
---|
| 34 | void i4_create_file_open_dialog(i4_graphical_style_class *style,
|
---|
| 35 | const i4_const_str &title_name,
|
---|
| 36 | const i4_const_str &start_dir,
|
---|
| 37 | const i4_const_str &file_mask,
|
---|
| 38 | const i4_const_str &mask_name,
|
---|
| 39 | i4_event_handler_class *tell_who,
|
---|
| 40 | w32 ok_id, w32 cancel_id)
|
---|
| 41 | {
|
---|
| 42 | char mname[256], m[256], tname[256], idir[256], fname[256], pcmd[1000];
|
---|
| 43 |
|
---|
| 44 | i4_os_string(mask_name, mname, sizeof(mname));
|
---|
| 45 | i4_os_string(file_mask, m, sizeof(m));
|
---|
| 46 | i4_os_string(title_name, tname, sizeof(tname));
|
---|
| 47 | i4_os_string(start_dir, idir, sizeof(idir));
|
---|
| 48 |
|
---|
| 49 | char *display=getenv("DISPLAY");
|
---|
| 50 | if (!display || display[0]==0)
|
---|
| 51 | display=":0.0";
|
---|
| 52 |
|
---|
| 53 | char *tmp_name="/tmp/open_filename.tmp";
|
---|
| 54 | sprintf(pcmd, "xgetfile -title \"%s\" -pattern \"%s\" -path \"%s\" -popup -display %s > %s",
|
---|
| 55 | tname, m, idir, display, tmp_name);
|
---|
| 56 |
|
---|
| 57 | unlink(tmp_name);
|
---|
| 58 | system(pcmd);
|
---|
| 59 | FILE *fp=fopen(tmp_name,"rb");
|
---|
| 60 | if (!fp || !fgets(m, 256, fp))
|
---|
| 61 | m[0]=0;
|
---|
| 62 | else
|
---|
| 63 | while (m[strlen(m)-1]=='\n')
|
---|
| 64 | m[strlen(m)-1]=0;
|
---|
| 65 |
|
---|
| 66 | if (fp) fclose(fp);
|
---|
| 67 | unlink(tmp_name);
|
---|
| 68 |
|
---|
| 69 |
|
---|
| 70 | char *s=m;
|
---|
| 71 |
|
---|
| 72 | if (*s==0 || *s=='\n')
|
---|
| 73 | {
|
---|
| 74 | i4_user_message_event_class o(cancel_id);
|
---|
| 75 | i4_kernel.send_event(tell_who, &o);
|
---|
| 76 | }
|
---|
| 77 | else
|
---|
| 78 | {
|
---|
| 79 | i4_file_open_message_class o(ok_id, new open_string(s));
|
---|
| 80 | i4_kernel.send_event(tell_who, &o);
|
---|
| 81 | }
|
---|
| 82 |
|
---|
| 83 |
|
---|
| 84 | }
|
---|
| 85 |
|
---|
| 86 |
|
---|
| 87 | class i4_get_save_dialog : public i4_color_window_class
|
---|
| 88 | {
|
---|
| 89 | i4_text_input_class *ti;
|
---|
| 90 | i4_graphical_style_class *style;
|
---|
| 91 | w32 ok_id, cancel_id;
|
---|
| 92 | i4_event_handler_class *tell_who;
|
---|
| 93 | public:
|
---|
| 94 | i4_parent_window_class *mp_window;
|
---|
| 95 |
|
---|
| 96 | enum { OK, CANCEL, CLOSE };
|
---|
| 97 |
|
---|
| 98 | i4_get_save_dialog(i4_const_str default_name,
|
---|
| 99 | i4_graphical_style_class *style,
|
---|
| 100 | w32 ok_id, w32 cancel_id,
|
---|
| 101 | i4_event_handler_class *tell_who)
|
---|
| 102 | : i4_color_window_class(0,0, style->color_hint->neutral(), style),
|
---|
| 103 | style(style),
|
---|
| 104 | ok_id(ok_id),
|
---|
| 105 | cancel_id(cancel_id),
|
---|
| 106 | tell_who(tell_who)
|
---|
| 107 | {
|
---|
| 108 | mp_window=0;
|
---|
| 109 | i4_create_dialog(i4gets("get_savename_dialog"),
|
---|
| 110 | this,
|
---|
| 111 | style,
|
---|
| 112 | &ti,
|
---|
| 113 | &default_name,
|
---|
| 114 | this, OK,
|
---|
| 115 | this, CANCEL);
|
---|
| 116 |
|
---|
| 117 | resize_to_fit_children();
|
---|
| 118 | }
|
---|
| 119 |
|
---|
| 120 | void receive_event(i4_event *ev)
|
---|
| 121 | {
|
---|
| 122 | if (ev->type()==i4_event::USER_MESSAGE)
|
---|
| 123 | {
|
---|
| 124 | CAST_PTR(uev, i4_user_message_event_class, ev);
|
---|
| 125 | if (uev->sub_type==OK) // tell who-ever what the user typed
|
---|
| 126 | {
|
---|
| 127 | i4_file_open_message_class o(ok_id,ti->get_edit_string());
|
---|
| 128 | i4_kernel.send_event(tell_who, &o);
|
---|
| 129 | }
|
---|
| 130 | else
|
---|
| 131 | {
|
---|
| 132 | i4_user_message_event_class c(cancel_id); // tell whoever the user canceled
|
---|
| 133 | i4_kernel.send_event(tell_who, &c);
|
---|
| 134 | }
|
---|
| 135 |
|
---|
| 136 | style->close_mp_window(mp_window); // close ourself
|
---|
| 137 | }
|
---|
| 138 | else i4_parent_window_class::receive_event(ev);
|
---|
| 139 | }
|
---|
| 140 |
|
---|
| 141 | char *name() { return "save dialog"; }
|
---|
| 142 | };
|
---|
| 143 |
|
---|
| 144 |
|
---|
| 145 |
|
---|
| 146 | void i4_create_file_save_dialog(i4_graphical_style_class *style,
|
---|
| 147 | const i4_const_str &default_name,
|
---|
| 148 | const i4_const_str &title_name,
|
---|
| 149 | const i4_const_str &start_dir,
|
---|
| 150 | const i4_const_str &file_mask,
|
---|
| 151 | const i4_const_str &mask_name,
|
---|
| 152 | i4_event_handler_class *tell_who,
|
---|
| 153 | w32 ok_id, w32 cancel_id)
|
---|
| 154 | {
|
---|
| 155 | i4_get_save_dialog *dlg=new i4_get_save_dialog(default_name, style,
|
---|
| 156 | ok_id, cancel_id, tell_who);
|
---|
| 157 |
|
---|
| 158 | i4_event_reaction_class *re;
|
---|
| 159 | re=new i4_event_reaction_class(dlg,
|
---|
| 160 | new i4_user_message_event_class(i4_get_save_dialog::CLOSE));
|
---|
| 161 |
|
---|
| 162 |
|
---|
| 163 | i4_parent_window_class *p;
|
---|
| 164 |
|
---|
| 165 | p=style->create_mp_window(-1, -1, dlg->width(), dlg->height(),
|
---|
| 166 | title_name,
|
---|
| 167 | re);
|
---|
| 168 |
|
---|
| 169 | p->add_child(0,0, dlg);
|
---|
| 170 | dlg->mp_window=p;
|
---|
| 171 | }
|
---|
| 172 |
|
---|