Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Oct 16th, 2005, 9:48 AM   #1
Simon Gray
Programmer
 
Join Date: Aug 2005
Location: Ålsgårde, Denmark
Posts: 62
Rep Power: 4 Simon Gray is on a distinguished road
Send a message via MSN to Simon Gray
Gtk#/Gtk trouble

The deal is, I'm trying to write a simple text-editor. When I use a TextView inside a ScrolledWindow, the ScrolledWindow doesn't automatically scroll down as new content is added at the end, which means you'll have to scroll down manually every time you write a new line.

I've tried hacking a solution together here like someone on #mono said I should do, but haven't had much luck. First of all, it scrolls to the bottom no matter what, doesn't matter if you're editing something 4 "pages" up... which sucks. Second of all, it doesn't count a single \n as changed content it seems so it's never completely scrolled down unless you write some characters.

I'm led to believe this way to go it completely wrong, does anyone know what to do? Doesn't matter if it's Gtk, Gtkmm or whatever you know.

using System;
using Gtk;

// A namespace with various classes to be used in a text-editing application
namespace TextEditing {
	
	// Main application, uses text-editing classes found in this namespace
	public class SmallTextEditor
	{	
		private Window app;
		private VBox mainBox;
		private ScrolledWindow scroll;
		private TextView textArea;
		private TextBuffer buffer;
		private Toolbar tools;
		private ToolButton newFileButton, openFileButton, saveFileButton;
		
		public SmallTextEditor(string[] args)
		{
			// Do useless stuff with the arguments (will be worked on later)
			foreach (string arg in args)
			{
				Console.WriteLine(arg);
			}
			
			Application.Init();
			
			// Window
			app = new Window("Small editor");
			app.DeleteEvent += new DeleteEventHandler(Exit);
			
			// Containers
			mainBox = new VBox(false, 0);
			scroll = new ScrolledWindow(null, null);
			scroll.SetPolicy(PolicyType.Automatic, PolicyType.Automatic);
			scroll.WindowPlacement = CornerType.BottomLeft;
			
			// Widgets
			textArea = new TextView();
			buffer = textArea.Buffer;
			buffer.Changed += new EventHandler(ScrollDown);
			//buffer.UserActionEnded += new EventHandler(ScrollDown);
			//buffer.UserActionBegun += new EventHandler(ScrollDown);
			tools = new Toolbar();
			
			newFileButton = new ToolButton(Stock.New);
			openFileButton = new ToolButton(Stock.Open);
			saveFileButton = new ToolButton(Stock.Save);
			
			
			// Adding to containers
			tools.Add(newFileButton);
			tools.Add(openFileButton);
			tools.Add(saveFileButton);
			
			scroll.AddWithViewport(textArea);
			
			mainBox.PackStart(tools, false, false, 0);
			mainBox.PackStart(scroll, true, true, 0);
			
			app.Add(mainBox);
			
			app.DefaultWidth = 400;
			app.DefaultHeight = 400;
			app.ShowAll();
			
			Application.Run();
		}
		
		public void ScrollDown(object obj, EventArgs args)
		{
			Console.WriteLine("adjusts");
			scroll.Vadjustment.Value = scroll.Vadjustment.Upper - scroll.Vadjustment.PageSize;
			
		}
		
		public void Exit(object obj, DeleteEventArgs args)
		{
			Application.Quit();
		}
	}
}

// Create an instance of the SmallTextEditor class
class UseTextEditing
{
	public static void Main(string[] args)
	{
		new TextEditing.SmallTextEditor(args);
	}
}
__________________
Visit my blog, about all that stuff in between your nostrils >_>
Simon Gray is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 1:08 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC