~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Linux Cross Reference
Tina6/tina-tools/tinatool/wdgts/gtk2/wdgtsGtk_tw_textsw.c

Version: ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /**********
  2  * 
  3  * Copyright (c) 2003, Division of Imaging Science and Biomedical Engineering,
  4  * University of Manchester, UK.  All rights reserved.
  5  * 
  6  * Redistribution and use in source and binary forms, with or without modification, 
  7  * are permitted provided that the following conditions are met:
  8  * 
  9  *   . Redistributions of source code must retain the above copyright notice, 
 10  *     this list of conditions and the following disclaimer.
 11  *    
 12  *   . Redistributions in binary form must reproduce the above copyright notice,
 13  *     this list of conditions and the following disclaimer in the documentation 
 14  *     and/or other materials provided with the distribution.
 15  * 
 16  *   . Neither the name of the University of Manchester nor the names of its
 17  *     contributors may be used to endorse or promote products derived from this 
 18  *     software without specific prior written permission.
 19  * 
 20  * 
 21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
 22  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
 23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
 24  * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 
 25  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
 26  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
 27  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 28  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
 29  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
 30  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
 31  * POSSIBILITY OF SUCH DAMAGE.
 32  *
 33  **********
 34  * 
 35  * Program :  TINA
 36  * File    :  $Source: /home/tina/cvs/tina-tools/tinatool/wdgts/gtk2/wdgtsGtk_tw_textsw.c,v $
 37  * Date    :  $Date: 2009/05/15 15:51:20 $
 38  * Version :  $Revision: 1.7 $
 39  * CVS Id  :  $Id: wdgtsGtk_tw_textsw.c,v 1.7 2009/05/15 15:51:20 paul Exp $
 40  *
 41  * Author  :  a.lacey@man.ac.uk, giob@man.ac.uk, paul.bromiley@manchester.ac.uk
 42  *
 43  *********
 44 */
 45 /** 
 46  *  @file  wdgtsGtk_tw_textsw.c
 47  *  @brief Define and create GTK text window and its writing functions.
 48  *
 49  *  Height adjustment is not provided if the window is resized.
 50  *  (Will do this only if there is time - GAB 13 Nov 2003).
 51  *
 52  *  Note that the functions in this file are duplicated for each widget set 
 53  *  (xv, GTK, xm, etc ...).
 54  */
 55 
 56 #include "wdgtsGtk_tw_textsw.h"
 57 
 58 #if HAVE_CONFIG_H
 59 #   include <config.h>
 60 #endif
 61 
 62 #include <stdio.h>
 63 #include <gtk/gtk.h>
 64 #include <tina/sys/sysGen_format.h>
 65 #include <tina/sys/sysGen_messages.h>
 66 #include <tina/sys/sysGen_error.h>
 67 #include <tinatool/wdgts/gtk2/wdgts_GtkDef.h>
 68 #include <tinatool/wdgts/gtk2/wdgtsGtk_tw_tool.h>
 69 
 70 static  GtkWidget  *textsw;
 71 
 72 
 73 /**
 74  * @brief  Write string to main text window.  
 75  * @param  string   String to display.
 76  * 
 77  * Text is black on current background and all chars inserted. 
 78  */
 79 void textsw_print(char *string)
 80 {
 81   GtkTextBuffer *text_buffer;
 82   GtkTextIter iter;
 83   GtkTextMark *mark;
 84 
 85   text_buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW (textsw));
 86   gtk_text_buffer_get_end_iter(text_buffer, &iter);
 87   gtk_text_buffer_insert(text_buffer, &iter, string, -1);
 88 
 89   gtk_text_buffer_get_end_iter(text_buffer, &iter);
 90   gtk_text_iter_set_line_offset(&iter, 0);
 91   mark = gtk_text_buffer_create_mark(text_buffer, "scroll", &iter, FALSE);
 92   gtk_text_view_scroll_mark_onscreen(GTK_TEXT_VIEW (textsw), mark);
 93   gtk_text_buffer_delete_mark(text_buffer, mark);
 94 }
 95 
 96 /**
 97  * @brief  Print to the specified text subwindow.  
 98  * @param  text_subwin  Void pointer to text subwindow.
 99  * @param  string       String to print.
100  */
101 void textsw_print_sw(void *text_subwin, char *string)
102 {
103   /* Note: this is only used in the help subwindow, and so doesn't do any scrolling 
104      (since the contents are always deleted prior to displaying a fresh help file.
105      The deletion causes problems with scrolling to marks (segfault), which I don't
106      entirely understand.  PAB 15/05/2009 */
107 
108   GtkTextBuffer *text_buffer;
109   GtkTextIter iter;
110   GtkTextMark *mark;
111 
112   text_buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW (text_subwin));
113   gtk_text_buffer_get_end_iter(text_buffer, &iter);
114   gtk_text_buffer_insert(text_buffer, &iter, string, -1);
115 }
116 
117 
118 /**
119  * @brief  Print to the specified text subwindow.  
120  * @param  text_subwin  Void pointer to text subwindow.
121  * @param  string       String to print.
122  *
123  * Only a wrapper for textsw_print_sw().
124  */
125 void tw_textsw_print(void *text_subwin, char *string)
126 {
127   textsw_print_sw(text_subwin, string);
128 }
129 
130 /**
131  * @brief  Create main text window.  
132  * @param  rows  Integer number of rows in window.
133  * @param  cols  Integer number of cols in window.
134  *
135  * Note that the text subwindow is packed in the main window vbox, not
136  * the current panel (hbox) as this would prevent vertical resizing.
137  * Moreover, the subwin is packed at the end of the vbox as it is more
138  * aesthetic to have the resizeable subwindow at the bottom.
139  */
140 GtkWidget *tw_textsubwin(int rows, int cols)
141 {
142   GtkWidget  *panel = (GtkWidget *)tw_get_vbox();
143   GtkWidget  *text;
144   GtkWidget  *box2, *table;
145   GtkWidget  *sw;
146 
147   box2 = gtk_vbox_new (FALSE, 0);
148   gtk_box_pack_start (GTK_BOX (panel), box2, TRUE, TRUE, 0);
149   gtk_widget_show (box2);
150   
151   table = gtk_table_new (2, 2, FALSE);
152   gtk_table_set_row_spacing (GTK_TABLE (table), 0, 0);
153   gtk_table_set_col_spacing (GTK_TABLE (table), 0, 0);
154   gtk_box_pack_end (GTK_BOX (box2), table, TRUE, TRUE, 0);
155   gtk_widget_show (table);
156   
157   /* Create the GtkText widget */
158   text = (GtkWidget *)gtk_text_view_new();
159   sw = gtk_scrolled_window_new(NULL, NULL);
160   gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw),
161                                   GTK_POLICY_AUTOMATIC,
162                                   GTK_POLICY_AUTOMATIC);
163   gtk_container_add(GTK_CONTAINER(sw), text);
164   gtk_widget_show(sw);
165 
166   gtk_widget_set_size_request (text, (gint) (cols * 4),  (gint) (rows * 20));
167   gtk_text_view_set_editable (GTK_TEXT_VIEW(text), FALSE);
168   gtk_table_attach (GTK_TABLE (table), sw, 0, 1, 0, 1,
169                     GTK_EXPAND | GTK_SHRINK | GTK_FILL,
170                     GTK_EXPAND | GTK_SHRINK | GTK_FILL, 0, 0);
171   gtk_widget_show (text);
172 
173   gtk_widget_realize(text);
174         
175   return (text);
176 }
177 
178 
179 
180 /**
181  * @brief  Create main text window AND redirect all Tina output to it.  
182  * @param  rows  Integer number of rows in window.
183  * @param  cols  Integer number of cols in window.
184  */
185 GtkWidget *tw_textsw(int rows, int cols)
186 {
187   textsw = tw_textsubwin(rows, cols);
188 
189   message_set_print(textsw_print); 
190   error_set_print(textsw_print);
191   format_set_print(textsw_print); 
192 
193   return(textsw);
194 }
195 
196 /**
197  * @brief  Clear the main text window.  
198  * @param  sw   Void pointer to a text window.
199  *
200  * Delete any text in the specified text subwindow: used in the help system PAB 15/05/2009
201  */
202 void tw_textsw_clear(void *sw)
203 {
204   GtkTextBuffer *text_buffer;
205   GtkTextIter start_iter, end_iter;
206 
207   text_buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW (sw));
208   gtk_text_buffer_get_bounds(text_buffer, &start_iter, &end_iter);
209   gtk_text_buffer_delete(text_buffer, &start_iter, &end_iter);
210 
211   /* Alternative method: set the text in the buffer to a NULL string  PAB 15/05/2009
212      gtk_text_buffer_set_text(text_buffer, "\0", -1); */
213 }
214 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.