netsurf/gtk/gtk_selection.c
Rob Kendrick e894e38c37 Merged revisions 4282-4285,4288-4293,4297-4298,4307,4309-4313,4322,4324-4431,4434-4494,4500-4508,4515,4517,4525-4545,4548-4555,4558-4572,4574-4576,4579,4582-4615,4618-4628,4630-4634,4636-4641,4643-4654,4656-4675,4677,4679-4685,4687-4750 via svnmerge from
svn://svn.netsurf-browser.org/branches/mikeL/netsurf

........
  r4689 | mikeL | 2008-07-17 19:59:20 +0100 (Thu, 17 Jul 2008) | 1 line
  
  Changed the toolbar at the bottom of the downloads dialog to a horizontal button box and added a 'Close' button (Based on a suggestion from the dev list). Internationalized the rest of the strings. Fixed many style errors (thanks rjek). Set authentication fields in the options dialog to be insensitive when proxy type is simple. Namespace'd the rest of download.h
........
  r4690 | mikeL | 2008-07-17 21:39:39 +0100 (Thu, 17 Jul 2008) | 1 line
  
  Removed close button. fixed text on resume button
........
  r4691 | mikeL | 2008-07-17 22:13:13 +0100 (Thu, 17 Jul 2008) | 1 line
  
  Added gtk downloads section
........
  r4715 | mikeL | 2008-07-20 19:41:39 +0100 (Sun, 20 Jul 2008) | 1 line
  
  Downloads are now automatically sorted (Downloading, Error'd, Completed, Canceled). New downloads appear at the beginning of the list. Removed leftover callback for close button. Downloads without a known total size are now handled correctly (bouncing progress block). Fixed bug where shift+click downloads would throw an error (encoding is now always set to binary).
........
  r4716 | mikeL | 2008-07-20 19:45:24 +0100 (Sun, 20 Jul 2008) | 1 line
  
  Removed unnecessary wndDownloads section
........
  r4717 | mikeL | 2008-07-20 19:53:44 +0100 (Sun, 20 Jul 2008) | 1 line
  
  Removed label on url in about dialog. Removed extra variable from the input callback. These changes should have already been committed a while back but for some reason they were skipped
........
  r4718 | mikeL | 2008-07-21 04:56:28 +0100 (Mon, 21 Jul 2008) | 1 line
  
  Total progress bar is now working and acts correctly with downloads of unknown size. All downloads are now stored in a GList (this will later make it possible to implement things like clearing all inactive downloads). Individual downloads no longer update themselves every .5 seconds, the function nsgtk_download_update is called using a g_timeout and cycles through the GList updating the total progress bar and each download. Downloads of unknown size now report their total size upon completion.
........
  r4719 | mikeL | 2008-07-21 05:06:17 +0100 (Mon, 21 Jul 2008) | 1 line
  
  Changed names of two functions that change sensitivity and status.
........
  r4720 | mikeL | 2008-07-21 16:56:41 +0100 (Mon, 21 Jul 2008) | 1 line
  
  Updated messages file
........
  r4722 | mikeL | 2008-07-21 21:44:23 +0100 (Mon, 21 Jul 2008) | 1 line
  
  Clear button now clears all inactive downloads when there is no selection.
........
  r4723 | mikeL | 2008-07-21 22:11:00 +0100 (Mon, 21 Jul 2008) | 1 line
  
  Fixed the total progress bar lagging behind events such as cancelations.
........
  r4727 | mikeL | 2008-07-23 19:33:53 +0100 (Wed, 23 Jul 2008) | 1 line
  
  Added an overwrite confirmation dialog for the 'save' button
........
  r4728 | mikeL | 2008-07-23 19:43:44 +0100 (Wed, 23 Jul 2008) | 1 line
  
  Save as dialog now starts in the default download directory instead of the user's home folder
........
  r4729 | mikeL | 2008-07-23 20:02:34 +0100 (Wed, 23 Jul 2008) | 1 line
  
  Updated Copyright information
........
  r4734 | mikeL | 2008-07-24 19:30:12 +0100 (Thu, 24 Jul 2008) | 1 line
  
  Fixed Info column not being set to expand
........

svn path=/trunk/netsurf/; revision=4752
2008-07-26 17:30:26 +00:00

111 lines
3.0 KiB
C

/*
* Copyright 2008 Mike Lester <element3260@gmail.com>
*
* This file is part of NetSurf, http://www.netsurf-browser.org/
*
* NetSurf 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; version 2 of the License.
*
* NetSurf is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <gtk/gtk.h>
#include "utils/log.h"
#include "desktop/gui.h"
#include "desktop/textinput.h"
#include "desktop/selection.h"
#include "desktop/browser.h"
#include "gtk/gtk_selection.h"
#include "gtk/gtk_window.h"
#include "utils/utf8.h"
static GString *current_selection = NULL;
static GtkClipboard *clipboard;
static bool copy_handler(const char *text, size_t length, struct box *box,
void *handle, const char *whitespace_text,
size_t whitespace_length);
bool gui_add_to_clipboard(const char *text, size_t length, bool space)
{
/* add the text from this box */
current_selection = g_string_append_len (current_selection,
text, length);
if (space) g_string_append (current_selection, " ");
return true;
}
bool copy_handler(const char *text, size_t length, struct box *box,
void *handle, const char *whitespace_text,
size_t whitespace_length)
{
/* add any whitespace which precedes the text from this box */
if (whitespace_text) {
if (!gui_add_to_clipboard(whitespace_text,
whitespace_length, false)) {
return false;
}
}
/* add the text from this box */
if (!gui_add_to_clipboard(text, length, box->space))
return false;
return true;
}
bool gui_copy_to_clipboard(struct selection *s)
{
clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
if (s->defined && selection_traverse(s, copy_handler, NULL))
gui_commit_clipboard();
return TRUE;
}
void gui_start_selection(struct gui_window *g)
{
if (current_selection == NULL)
current_selection = g_string_new(NULL);
else
g_string_set_size(current_selection, 0);
gtk_widget_grab_focus(GTK_WIDGET(g->drawing_area));
}
void gui_paste_from_clipboard(struct gui_window *g, int x, int y)
{
gchar *text;
clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
text = gtk_clipboard_wait_for_text (clipboard);
/* clipboard_wait... converts the string to utf8 for us */
if (text != NULL)
browser_window_paste_text(g->bw, text, strlen(text), true);
g_free(text);
}
bool gui_empty_clipboard(void)
{
if (!current_selection)
current_selection = g_string_new(NULL);
else
g_string_set_size(current_selection, 0);
return true;
}
bool gui_commit_clipboard(void)
{
clipboard = gtk_clipboard_get(GDK_SELECTION_CLIPBOARD);
gtk_clipboard_set_text(clipboard, current_selection->str, -1);
return true;
}