medit/tests/mterm.c

111 lines
3.3 KiB
C
Raw Normal View History

2005-06-23 13:18:45 -07:00
/*
* tests/mterm.c
2005-06-23 13:18:45 -07:00
*
* Copyright (C) 2004-2006 by Yevgen Muntyan <muntyan@math.tamu.edu>
2005-06-23 13:18:45 -07:00
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* See COPYING file that comes with this distribution.
*/
2005-06-22 11:20:32 -07:00
#include <gtk/gtk.h>
#include "mooterm/mooterm.h"
#include "mooutils/mooutils-misc.h"
2005-06-22 11:20:32 -07:00
#include <string.h>
#include <stdlib.h>
2005-06-23 13:18:45 -07:00
static void
init (int *argc, char ***argv, const char **cmd)
2005-07-22 02:49:39 -07:00
{
int i;
gboolean gdk_debug = FALSE;
gtk_init (argc, argv);
for (i = 1; i < *argc; ++i)
{
if (!strcmp ((*argv)[i], "--gdk-debug"))
gdk_debug = TRUE;
else
*cmd = (*argv)[i];
}
if (gdk_debug)
gdk_window_set_debug_updates (TRUE);
2006-03-24 16:51:31 -08:00
// moo_set_log_func_file ("/tmp/mterm");
2005-07-22 02:49:39 -07:00
}
static void
set_width (MooTerm *term, guint width, GtkWindow *window)
2005-07-21 15:11:16 -07:00
{
guint height;
height = moo_term_char_height (term) * 25;
width *= moo_term_char_width (term);
2005-07-21 15:11:16 -07:00
gtk_widget_set_size_request (GTK_WIDGET (term), width, height);
gtk_window_resize (window, 10, 10);
gtk_container_check_resize (GTK_CONTAINER (window));
gdk_window_process_updates (GTK_WIDGET(window)->window, TRUE);
}
2005-06-22 15:13:12 -07:00
int main (int argc, char *argv[])
2005-06-22 11:20:32 -07:00
{
const char *cmd = NULL;
2005-06-23 13:18:45 -07:00
GtkWidget *win, *swin, *term;
2005-07-22 02:49:39 -07:00
init (&argc, &argv, &cmd);
if (!cmd)
2005-06-22 15:13:12 -07:00
{
cmd = g_getenv ("SHELL");
if (!cmd)
cmd = "sh";
2005-06-22 11:20:32 -07:00
}
2005-06-23 13:18:45 -07:00
win = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_window_set_default_size (GTK_WINDOW (win), 700, 500);
2005-06-23 13:18:45 -07:00
swin = gtk_scrolled_window_new (NULL, NULL);
2005-06-22 11:20:32 -07:00
gtk_container_add (GTK_CONTAINER (win), swin);
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (swin),
GTK_POLICY_NEVER,
// GTK_POLICY_NEVER);
// GTK_POLICY_AUTOMATIC);
GTK_POLICY_ALWAYS);
2005-06-22 11:20:32 -07:00
2005-07-20 08:52:15 -07:00
term = GTK_WIDGET (g_object_new (MOO_TYPE_TERM,
2005-07-21 15:11:16 -07:00
"cursor-blinks", FALSE,
"font-name", "Courier New 11",
2005-07-20 08:52:15 -07:00
NULL));
2005-07-21 15:11:16 -07:00
2005-06-22 11:20:32 -07:00
gtk_container_add (GTK_CONTAINER (swin), term);
gtk_widget_show_all (win);
2005-07-21 15:11:16 -07:00
gtk_container_set_resize_mode (GTK_CONTAINER (win),
GTK_RESIZE_IMMEDIATE);
gtk_container_set_resize_mode (GTK_CONTAINER (swin),
GTK_RESIZE_IMMEDIATE);
2005-06-22 11:20:32 -07:00
2005-07-21 15:11:16 -07:00
g_signal_connect (term, "set-width",
G_CALLBACK (set_width), win);
g_signal_connect_swapped (term, "set-window-title",
G_CALLBACK (gtk_window_set_title), win);
g_signal_connect_swapped (term, "set-icon-name",
G_CALLBACK (gdk_window_set_icon_name), win->window);
2005-07-31 07:53:10 -07:00
moo_term_fork_command_line (MOO_TERM (term), cmd, NULL, NULL, NULL);
2005-06-22 11:20:32 -07:00
2005-07-14 23:39:21 -07:00
g_signal_connect (win, "destroy", gtk_main_quit, NULL);
g_signal_connect_swapped (term, "child-died",
G_CALLBACK (gtk_widget_destroy), win);
g_signal_connect (term, "bell", G_CALLBACK (gdk_beep), NULL);
2005-06-22 11:20:32 -07:00
gtk_main ();
2005-08-26 01:37:34 -07:00
return 0;
2005-06-22 11:20:32 -07:00
}