123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488 |
-
- #include <config.h>
- #include <stdarg.h>
- #include <string.h>
- #include <ctype.h>
- #include "main.h"
- #include "tkmain.h"
- #include "key.h"
- #include "global.h"
- #include "tty.h"
- Tcl_Interp *interp;
- int use_one_window = 1;
- static char *display = NULL;
- static int mi_getch_waiting = 0;
- static int mi_getch_value;
- static Tk_ArgvInfo arg_table[] = {
- {"-display", TK_ARGV_STRING, (char *) NULL, (char *) &display,
- "Display to use"},
- {(char *) NULL, TK_ARGV_END, (char *) NULL, (char *) NULL,
- (char *) NULL}
- };
- static int tkmc_callback (ClientData cd, Tcl_Interp *i, int ac, char *av[]);
- char *ALPHA =
- "\n\n"
- "\n\t\t\t*** IMPORTANT ***\n\n"
- "The Tk edition of the Midnight Commander is an ALPHA release of the code.\n\n"
- "Many features are missing and in general, not all of the features that\n"
- "are available in the text mode version of the program are available on\n"
- "this edition.\n\n"
- "The internal viewer is incomplete, the built-in editor does not work\n"
- "the Tree widget does not work, the Info Widget is incomplete, the setup\n"
- "code is incomplete, the keybindings are incomplete, and little testing\n"
- "has been done in this code. ** This is not a finished product **\n\n"
- "Feel free to send fixes to mc-devel@nuclecu.unam.mx\n\n\n";
- int
- xtoolkit_init (int *argc, char *argv[])
- {
- interp = Tcl_CreateInterp ();
- if (Tk_ParseArgv (interp, (Tk_Window) NULL, argc, argv, arg_table, 0)
- != TCL_OK) {
- fprintf(stderr, "%s\n", interp->result);
- exit(1);
- }
- printf (ALPHA);
- COLS = 80;
- LINES = 25;
-
- if (display != NULL) {
- Tcl_SetVar2 (interp, "env", "DISPLAY", display, TCL_GLOBAL_ONLY);
- }
- Tcl_SetVar(interp, "tcl_interactive", "0", TCL_GLOBAL_ONLY);
-
- Tcl_SetVar (interp, "LIBDIR", mc_home, TCL_GLOBAL_ONLY);
- Tcl_SetVar (interp, "mc_running", "1", TCL_GLOBAL_ONLY);
-
- Tcl_SetVar(interp, "one_window",
- use_one_window ? "1" : "0", TCL_GLOBAL_ONLY);
-
- #ifdef OLD_VERSION
- tkwin = Tk_CreateMainWindow (interp, display, "Midnight Commander","tkmc");
- #endif
- if (Tcl_Init (interp) != TCL_OK){
- fprintf (stderr, "Tcl_Init: %s\n", interp->result);
- exit (1);
- }
- if (Tk_Init (interp) != TCL_OK){
- fprintf (stderr, "Tk_Init: %s\n", interp->result);
- exit (1);
- }
- #ifdef HAVE_BLT
- give an error here
- if (Blt_DragDropInit (interp) != TCL_OK){
- fprintf (stderr, "Blt_DragDropInit: %s\n", interp->result);
- exit (1);
- }
- Tcl_SetVar (interp, "have_blt", "1", TCL_GLOBAL_ONLY);
- #else
- Tcl_SetVar (interp, "have_blt", "0", TCL_GLOBAL_ONLY);
- #endif
-
- Tcl_CreateCommand (interp, "tkmc", tkmc_callback, 0, 0);
- {
- char *mc_tcl = concat_dir_and_file (mc_home, "mc.tcl");
-
- if (Tcl_EvalFile (interp, mc_tcl) == TCL_OK){
- free (mc_tcl);
- return 0;
- } else {
- printf ("%s\n", interp->result);
- exit (1);
- }
- }
- }
- int
- xtoolkit_end (void)
- {
-
- Tcl_Eval (interp, "exit");
- return 1;
- }
- void
- tk_evalf (char *format, ...)
- {
- va_list ap;
- char buffer [1024];
- va_start (ap, format);
- vsprintf (buffer, format, ap);
- if (Tcl_Eval (interp, buffer) != TCL_OK){
- fprintf (stderr, "[%s]: %s\n", buffer, interp->result);
- }
- va_end (ap);
- }
- int
- tk_evalf_val (char *format, ...)
- {
- va_list ap;
- char buffer [1024];
- int r;
- va_start (ap, format);
- vsprintf (buffer, format, ap);
- r = Tcl_Eval (interp, buffer);
- va_end (ap);
- return r;
- }
- widget_data
- xtoolkit_create_dialog (Dlg_head *h, int flags)
- {
- char *dialog_name = copy_strings (".", h->name, 0);
- tk_evalf ("toplevel %s", dialog_name);
- h->grided = flags & DLG_GRID;
- if (h->grided)
- tk_evalf ("create_gui_canvas %s", dialog_name);
- return (widget_data) dialog_name;
- }
- void
- x_set_dialog_title (Dlg_head *h, char *title)
- {
- tk_evalf ("wm title %s {%s}", (char *)(h->wdata), title);
- }
- widget_data
- xtoolkit_get_main_dialog (Dlg_head *h)
- {
- return (widget_data) strdup (".");
- }
- widget_data
- x_create_panel_container (int which)
- {
- char *s, *cmd;
- cmd = use_one_window ? "frame" : "toplevel";
- s = which ? ".right" : ".left";
- tk_evalf ("%s %s", cmd, s);
- s = which ? ".right.canvas" : ".left.canvas";
- tk_evalf ("create_container %s", s);
- return (widget_data) s;
- }
- void
- x_panel_container_show (widget_data wdata)
- {
- }
- static int
- do_esc_key (int d)
- {
- if (isdigit(d))
- return KEY_F(d-'0');
- if ((d >= 'a' && d <= 'z') || (d >= 'A' && d <= 'Z' )
- || d == '\n' || d == '\t' || d == XCTRL ('h') || d == '!'
- || d == KEY_BACKSPACE || d == 127 || d == '\r')
- return ALT(d);
- else {
- return ESC_CHAR;
- }
- }
-
- static int
- tkmc_callback (ClientData cd, Tcl_Interp *i, int ac, char *av[])
- {
- Dlg_head *h = current_dlg;
- int key;
- static int got_esc;
- key = av [2][0];
-
- if (av [1][0] == 'c' || av [1][0] == 'a'){
- if (!key)
- return TCL_OK;
-
-
-
- if (!isascii (key)){
- return TCL_OK;
- } else {
- key = tolower (key);
- }
- }
- switch (av [1][0]){
- case 'a':
- key = ALT(key);
- break;
- case 'c':
- key = XCTRL(key);
- break;
- case 'r':
- if (!key)
- return TCL_OK;
- break;
-
- case 'k':
- if (!(key = lookup_keysym (av [2])))
- return TCL_OK;
- break;
- case 'e':
- key = ESC_CHAR;
- dlg_key_event (h, key);
- update_cursor (h);
- return TCL_OK;
- }
-
- if (key == '\r')
- key = '\n';
- if (key == ESC_CHAR){
- if (!got_esc){
- got_esc = 1;
- return TCL_OK;
- }
- got_esc = 0;
- }
- if (got_esc){
- key = do_esc_key (key);
- got_esc = 0;
- }
- if (mi_getch_waiting && key){
- mi_getch_waiting = 0;
- mi_getch_value = key;
- return TCL_OK;
- }
- dlg_key_event (h, key);
- update_cursor (h);
- return TCL_OK;
- }
- void
- x_focus_widget (Widget_Item *p)
- {
- char *wname;
- if (!p->widget)
- return;
-
- wname = (char *) p->widget->wdata;
- if (!wname)
- return;
- tk_evalf ("focus %s", wname+1);
- }
- void
- x_unfocus_widget (Widget_Item *p)
- {
- }
- void
- x_init_dlg (Dlg_head *h)
- {
- Widget_Item *h_track;
- char *top_level_name;
- int grided;
- int i;
-
- h_track = h->current;
- grided = h->grided;
- top_level_name = (char *) h->wdata;
-
-
- if (grided){
- tk_evalf ("set components {}");
- for (i = 0; i < h->count; i++){
- tk_evalf ("set components \"%s $components\"", h_track->widget->tkname);
- h_track = h_track->prev;
- }
- tk_evalf ("layout_with_grid %s %d", h->name, h->count);
- if (atoi (interp->result) == 0){
- tk_evalf ("run_gui_design .%s", h->name);
-
- while (1)
- Tcl_DoOneEvent (TCL_ALL_EVENTS);
- }
- } else {
- tk_evalf ("set wlist {}");
- for (i = 0; i < h->count; i++){
- char *wname = (char *)h_track->widget->wdata;
-
- if (wname)
- tk_evalf ("set wlist \"%s $wlist\"", wname+1);
- h_track = h_track->prev;
- }
- tk_evalf ("layout_%s", h->name);
- }
-
- tk_evalf ("bind_setup %s", top_level_name);
-
- if (top_level_name [0] && top_level_name [1]){
- tk_evalf ("center_win %s", top_level_name);
- }
- }
- int
- tkrundlg_event (Dlg_head *h)
- {
-
- while (h->running){
- if (h->send_idle_msg){
- if (Tcl_DoOneEvent (TCL_DONT_WAIT))
- if (idle_hook)
- execute_hooks (idle_hook);
-
- while (Tcl_DoOneEvent (TCL_DONT_WAIT) &&
- h->running && h->send_idle_msg){
- (*h->callback) (h, 0, DLG_IDLE);
- }
- } else
- Tcl_DoOneEvent (TCL_ALL_EVENTS);
- }
- return 1;
- }
- int
- Tcl_AppInit (Tcl_Interp *interp)
- {
- return TCL_OK;
- }
- void
- x_interactive_display ()
- {
- }
- int
- tk_getch ()
- {
- mi_getch_waiting = 1;
-
- while (mi_getch_waiting)
- Tk_DoOneEvent (TK_ALL_EVENTS);
-
- return mi_getch_value;
- }
- void
- tk_dispatch_all (void)
- {
- while (Tk_DoOneEvent (TK_DONT_WAIT))
- ;
- }
- void
- x_destroy_dlg_start (Dlg_head *h)
- {
-
- }
- void
- x_destroy_dlg (Dlg_head *h)
- {
- tk_evalf ("destroy %s", (char *) h->wdata);
- tk_dispatch_all ();
- free ((char *) h->wdata);
- tk_end_frame ();
- }
- void
- edition_post_exec (void)
- {
- if (iconify_on_exec)
- tk_evalf ("wm deiconify .");
- }
- void
- edition_pre_exec (void)
- {
- if (iconify_on_exec)
- tk_evalf ("wm iconify .");
- }
- int
- try_alloc_color_pair (char *fg, char *bg)
- {
- }
|