1 | /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ |
---|
2 | /* This file is part of the GtkHTML library |
---|
3 | |
---|
4 | Copyright (C) 2000 Helix Code, Inc. |
---|
5 | |
---|
6 | This library is free software; you can redistribute it and/or |
---|
7 | modify it under the terms of the GNU Library General Public |
---|
8 | License as published by the Free Software Foundation; either |
---|
9 | version 2 of the License, or (at your option) any later version. |
---|
10 | |
---|
11 | This library is distributed in the hope that it will be useful, |
---|
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
14 | Library General Public License for more details. |
---|
15 | |
---|
16 | You should have received a copy of the GNU Library General Public License |
---|
17 | along with this library; see the file COPYING.LIB. If not, write to |
---|
18 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
---|
19 | Boston, MA 02111-1307, USA. |
---|
20 | */ |
---|
21 | |
---|
22 | #include <config.h> |
---|
23 | #include <ctype.h> |
---|
24 | #include "htmlcursor.h" |
---|
25 | #include "htmlengine-edit-text.h" |
---|
26 | #include "htmlengine-edit-movement.h" |
---|
27 | #include "htmlengine-edit.h" |
---|
28 | #include "htmlselection.h" |
---|
29 | #include "htmltext.h" |
---|
30 | #include "htmlundo.h" |
---|
31 | |
---|
32 | static gboolean |
---|
33 | find_first (HTMLEngine *e) |
---|
34 | { |
---|
35 | guchar c; |
---|
36 | |
---|
37 | c = html_cursor_get_current_char (e->cursor); |
---|
38 | while (c == 0 || ! g_unichar_isalnum (c) || c == ' ') { |
---|
39 | if (!html_cursor_forward (e->cursor, e)) |
---|
40 | return FALSE; |
---|
41 | c = html_cursor_get_current_char (e->cursor); |
---|
42 | } |
---|
43 | |
---|
44 | return TRUE; |
---|
45 | } |
---|
46 | |
---|
47 | static void |
---|
48 | upper_lower (HTMLObject *obj, HTMLEngine *e, gpointer data) |
---|
49 | { |
---|
50 | if (html_object_is_text (obj)) { |
---|
51 | gboolean up = GPOINTER_TO_INT (data); |
---|
52 | guchar *text; |
---|
53 | |
---|
54 | text = HTML_TEXT (obj)->text; |
---|
55 | while (*text) { |
---|
56 | *text = (up) ? toupper (*text) : tolower (*text); |
---|
57 | text++; |
---|
58 | } |
---|
59 | } |
---|
60 | } |
---|
61 | |
---|
62 | void |
---|
63 | html_engine_capitalize_word (HTMLEngine *e) |
---|
64 | { |
---|
65 | if (find_first (e)) { |
---|
66 | guchar c; |
---|
67 | |
---|
68 | html_undo_level_begin (e->undo, "Capitalize word", "Revert word capitalize"); |
---|
69 | html_engine_set_mark (e); |
---|
70 | html_cursor_forward (e->cursor, e); |
---|
71 | html_engine_cut_and_paste (e, "up 1st", "revert up 1st", |
---|
72 | upper_lower, GINT_TO_POINTER (TRUE)); |
---|
73 | html_engine_disable_selection (e); |
---|
74 | |
---|
75 | c = html_cursor_get_current_char (e->cursor); |
---|
76 | if (g_unichar_isalnum (c)) { |
---|
77 | html_engine_set_mark (e); |
---|
78 | html_engine_forward_word (e); |
---|
79 | html_engine_cut_and_paste (e, "down rest", "revert down rest", |
---|
80 | upper_lower, GINT_TO_POINTER (FALSE)); |
---|
81 | html_engine_disable_selection (e); |
---|
82 | } |
---|
83 | html_undo_level_end (e->undo); |
---|
84 | } |
---|
85 | } |
---|
86 | |
---|
87 | void |
---|
88 | html_engine_upcase_downcase_word (HTMLEngine *e, gboolean up) |
---|
89 | { |
---|
90 | if (find_first (e)) { |
---|
91 | html_engine_set_mark (e); |
---|
92 | html_engine_forward_word (e); |
---|
93 | html_engine_cut_and_paste (e, |
---|
94 | up ? "Upcase word" : "Downcase word", |
---|
95 | up ? "Revert word upcase" : "Revert word downcase", |
---|
96 | upper_lower, GINT_TO_POINTER (up)); |
---|
97 | html_engine_disable_selection (e); |
---|
98 | } |
---|
99 | } |
---|