summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Young <chris@unsatisfactorysoftware.co.uk>2010-07-24 19:57:27 +0000
committerChris Young <chris@unsatisfactorysoftware.co.uk>2010-07-24 19:57:27 +0000
commitf7e32547987a23148cdf292d8b08733ad3f77409 (patch)
treef0eb7b77d1611a9dc2b9b845bf76a3d1a4edaea6
parent004aee8281895120f69bb83559278c17805584cd (diff)
downloadnetsurf-f7e32547987a23148cdf292d8b08733ad3f77409.tar.gz
netsurf-f7e32547987a23148cdf292d8b08733ad3f77409.tar.bz2
Fix menu disable on tab switch and Cut
svn path=/trunk/netsurf/; revision=10661
-rwxr-xr-xamiga/clipboard.c75
-rwxr-xr-xamiga/clipboard.h1
-rwxr-xr-xamiga/context_menu.c1
-rwxr-xr-xamiga/gui.c52
-rwxr-xr-xamiga/gui.h3
-rwxr-xr-xamiga/menu.c54
-rwxr-xr-xamiga/menu.h2
7 files changed, 120 insertions, 68 deletions
diff --git a/amiga/clipboard.c b/amiga/clipboard.c
index 01b813667..6ec1b2a39 100755
--- a/amiga/clipboard.c
+++ b/amiga/clipboard.c
@@ -19,6 +19,7 @@
#include "desktop/gui.h"
#include "utils/utf8.h"
#include "desktop/selection.h"
+#include "desktop/textinput.h"
#include "amiga/iff_cset.h"
#include "amiga/options.h"
@@ -40,6 +41,8 @@
struct IFFHandle *iffh = NULL;
+bool ami_add_to_clipboard(const char *text, size_t length, bool space);
+
void ami_clipboard_init(void)
{
if(iffh = AllocIFF())
@@ -132,12 +135,62 @@ void gui_paste_from_clipboard(struct gui_window *g, int x, int y)
bool gui_empty_clipboard(void)
{
+ /* Put a half-completed FTXT on the clipboard and leave it open for more additions */
+
+ struct CSet cset = {0};
+
+ if(!(OpenIFF(iffh,IFFF_WRITE)))
+ {
+ if(!(PushChunk(iffh,ID_FTXT,ID_FORM,IFFSIZE_UNKNOWN)))
+ {
+ if(option_utf8_clipboard)
+ {
+ if(!(PushChunk(iffh,0,ID_CSET,24)))
+ {
+ cset.CodeSet = 106; // UTF-8
+ WriteChunkBytes(iffh,&cset,24);
+ PopChunk(iffh);
+ }
+ }
+ }
+ else
+ {
+ PopChunk(iffh);
+ }
+// CloseIFF(iffh);
+ }
return true;
}
bool gui_add_to_clipboard(const char *text, size_t length, bool space)
{
+ /* This might crash or at least not work if gui_empty_clipboard isn't called first,
+ and gui_commit_clipboard after.
+ These only seem to be called from desktop/textinput.c in this specific order, if they
+ are added elsewhere this might need a rewrite. */
+
+ if(!(PushChunk(iffh,0,ID_CHRS,IFFSIZE_UNKNOWN)))
+ {
+ if(text)
+ {
+ if(!ami_add_to_clipboard(text, length, false)) return false;
+ }
+
+ PopChunk(iffh);
+ }
+ else
+ {
+ PopChunk(iffh);
+ return false;
+ }
+
+ return true;
+}
+
+bool ami_add_to_clipboard(const char *text, size_t length, bool space)
+{
char *buffer;
+
if(option_utf8_clipboard)
{
WriteChunkBytes(iffh,text,length);
@@ -168,12 +221,12 @@ bool ami_clipboard_copy(const char *text, size_t length, struct box *box,
{
if (whitespace_text)
{
- if(!gui_add_to_clipboard(whitespace_text,whitespace_length, false)) return false;
+ if(!ami_add_to_clipboard(whitespace_text,whitespace_length, false)) return false;
}
if(text)
{
- if (!gui_add_to_clipboard(text, length, box->space)) return false;
+ if (!ami_add_to_clipboard(text, length, box->space)) return false;
}
PopChunk(iffh);
@@ -221,6 +274,22 @@ bool gui_copy_to_clipboard(struct selection *s)
return false;
}
+void ami_drag_selection(struct selection *s)
+{
+ struct box *text_box;
+ ULONG x = s->bw->window->shared->win->MouseX;
+ ULONG y = s->bw->window->shared->win->MouseY;
+
+ if(text_box = ami_text_box_at_point(s->bw->window, &x, &y))
+ {
+ if(gui_copy_to_clipboard(s))
+ {
+ browser_window_mouse_click(s->bw, BROWSER_MOUSE_PRESS_1, x, y);
+ browser_window_key_press(s->bw, KEY_PASTE);
+ }
+ }
+}
+
bool ami_easy_clipboard(char *text)
{
struct CSet cset = {0};
@@ -241,7 +310,7 @@ bool ami_easy_clipboard(char *text)
if(!(PushChunk(iffh,0,ID_CHRS,IFFSIZE_UNKNOWN)))
{
- if(gui_add_to_clipboard(text,strlen(text),false))
+ if(ami_add_to_clipboard(text,strlen(text),false))
{
PopChunk(iffh);
gui_commit_clipboard();
diff --git a/amiga/clipboard.h b/amiga/clipboard.h
index 887015d21..75524e9fd 100755
--- a/amiga/clipboard.h
+++ b/amiga/clipboard.h
@@ -21,6 +21,7 @@
void ami_clipboard_init(void);
void ami_clipboard_free(void);
+void ami_drag_selection(struct selection *s);
bool ami_easy_clipboard(char *text);
bool ami_easy_clipboard_bitmap(struct bitmap *bitmap);
#ifdef WITH_NS_SVG
diff --git a/amiga/context_menu.c b/amiga/context_menu.c
index 6a53248ec..12df13aac 100755
--- a/amiga/context_menu.c
+++ b/amiga/context_menu.c
@@ -385,7 +385,6 @@ uint32 ami_context_menu_hook(struct Hook *hook,Object *item,APTR reserved)
break;
case CMID_SELCUT:
- browser_window_key_press(gwin->bw, KEY_COPY_SELECTION);
browser_window_key_press(gwin->bw, KEY_CUT_SELECTION);
break;
diff --git a/amiga/gui.c b/amiga/gui.c
index 82a3a428d..248b59dd0 100755
--- a/amiga/gui.c
+++ b/amiga/gui.c
@@ -1293,7 +1293,6 @@ void ami_handle_msg(void)
case 'x':
browser_window_key_press(gwin->bw, KEY_CUT_SELECTION);
- browser_window_key_press(gwin->bw, KEY_CLEAR_SELECTION);
break;
case 'c':
@@ -1910,7 +1909,7 @@ void ami_switch_tab(struct gui_window_2 *gwin,bool redraw)
}
ami_update_buttons(gwin);
- ami_menu_update_disabled(gwin->win, gwin->bw->current_content);
+ ami_menu_update_disabled(gwin->bw->window, gwin->bw->current_content);
if(redraw)
{
@@ -3662,7 +3661,7 @@ void gui_window_new_content(struct gui_window *g)
if(g->shared->bw->browser_window_type != BROWSER_WINDOW_NORMAL ||
option_kiosk_mode == true) return;
- ami_menu_update_disabled(g->shared->win, c);
+ ami_menu_update_disabled(g, c);
}
bool gui_window_scroll_start(struct gui_window *g)
@@ -3782,34 +3781,13 @@ uint32 ami_popup_hook(struct Hook *hook,Object *item,APTR reserved)
return itemid;
}
-/* Below two are more suited to clipboard.c but use some functions internal to gui.c,
- so we put them here. */
-
-bool ami_drag_selection_paste(const char *text, size_t length, struct box *box,
- void *handle, const char *whitespace_text,size_t whitespace_length)
-{
- struct browser_window *bw = handle;
-
-printf("dspaste\n");
-
- if(whitespace_text)
- {
- browser_window_paste_text(bw, whitespace_text, whitespace_length, true);
- }
-
- if(text)
- {
- browser_window_paste_text(bw, text, length, true);
- }
-
- return true;
-}
+/* return the text box at posn x,y in window coordinates
+ x,y are updated to be document co-ordinates */
-void ami_drag_selection(struct selection *s)
+struct box *ami_text_box_at_point(struct gui_window *g, ULONG *x, ULONG *y)
{
- struct gui_window *g = s->bw->window;
struct IBox *bbox;
- ULONG x,y,xs,ys,width,height;
+ ULONG xs,ys,width,height;
struct box *box,*text_box=0;
hlcache_handle *content;
int box_x=0,box_y=0;
@@ -3818,17 +3796,17 @@ void ami_drag_selection(struct selection *s)
(ULONG *)&bbox);
ami_get_hscroll_pos(g->shared, (ULONG *)&xs);
- x = (s->bw->window->shared->win->MouseX) - (bbox->Left) +xs;
+ *x = *x - (bbox->Left) +xs;
ami_get_vscroll_pos(g->shared, (ULONG *)&ys);
- y = (s->bw->window->shared->win->MouseY) - bbox->Top + ys;
+ *y = *y - (bbox->Top) + ys;
width=bbox->Width;
height=bbox->Height;
- content = s->bw->current_content;
+ content = g->shared->bw->current_content;
box = html_get_box_tree(content);
- while ((box = box_at_point(box, x, y, &box_x, &box_y, &content)))
+ while ((box = box_at_point(box, *x, *y, &box_x, &box_y, &content)))
{
if (box->style && css_computed_visibility(box->style) == CSS_VISIBILITY_HIDDEN) continue;
@@ -3847,13 +3825,5 @@ void ami_drag_selection(struct selection *s)
}
}
}
-
- if(text_box)
- {
- if(gui_copy_to_clipboard(s))
- {
- browser_window_mouse_click(s->bw, BROWSER_MOUSE_PRESS_1, x, y);
- browser_window_key_press(s->bw, KEY_PASTE);
- }
- }
+ return text_box;
}
diff --git a/amiga/gui.h b/amiga/gui.h
index a291649f0..2a961f62c 100755
--- a/amiga/gui.h
+++ b/amiga/gui.h
@@ -127,8 +127,7 @@ void ami_close_all_tabs(struct gui_window_2 *gwin);
void ami_quit_netsurf(void);
void ami_do_redraw(struct gui_window_2 *g);
STRPTR ami_locale_langs(void);
-
-void ami_drag_selection(struct selection *s);
+struct box *ami_text_box_at_point(struct gui_window *g, ULONG *x, ULONG *y);
struct TextFont *origrpfont;
struct MinList *window_list;
diff --git a/amiga/menu.c b/amiga/menu.c
index c692c6983..d338d3766 100755
--- a/amiga/menu.c
+++ b/amiga/menu.c
@@ -16,40 +16,44 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#include "desktop/browser.h"
+#include <string.h>
+
+#include <proto/dos.h>
+#include <proto/asl.h>
+#include <proto/exec.h>
+#include <proto/intuition.h>
+#include <dos/anchorpath.h>
+#include <libraries/gadtools.h>
+
#include "amiga/menu.h"
-#include "utils/messages.h"
#include "amiga/utf8.h"
-#include <libraries/gadtools.h>
-#include <proto/asl.h>
#include "amiga/options.h"
-#include "desktop/gui.h"
#include "amiga/hotlist.h"
-#include <proto/dos.h>
#include "amiga/gui.h"
#include "amiga/save_pdf.h"
-#include "desktop/save_text.h"
-#include "desktop/save_pdf/pdf_plotters.h"
-#include "desktop/save_complete.h"
-#include <string.h>
#include "amiga/tree.h"
#include "amiga/history.h"
#include "amiga/cookies.h"
-#include <proto/exec.h>
#include "amiga/arexx.h"
-#include "utils/url.h"
-#include <dos/anchorpath.h>
-#include "desktop/textinput.h"
#include "amiga/search.h"
#include "amiga/history_local.h"
#include "amiga/bitmap.h"
#include "amiga/iff_dr2d.h"
#include "amiga/clipboard.h"
-#include "content/fetch.h"
#include "amiga/gui_options.h"
#include "amiga/print.h"
#include "amiga/download.h"
-#include <proto/intuition.h>
+
+#include "content/fetch.h"
+#include "desktop/browser.h"
+#include "desktop/gui.h"
+#include "desktop/save_text.h"
+#include "desktop/save_pdf/pdf_plotters.h"
+#include "desktop/save_complete.h"
+#include "desktop/selection.h"
+#include "desktop/textinput.h"
+#include "utils/messages.h"
+#include "utils/url.h"
BOOL menualreadyinit;
const char * const netsurf_version;
@@ -634,7 +638,6 @@ void ami_menupick(ULONG code,struct gui_window_2 *gwin,struct MenuItem *item)
switch(itemnum)
{
case 0: // cut
- browser_window_key_press(gwin->bw, KEY_COPY_SELECTION);
browser_window_key_press(gwin->bw, KEY_CUT_SELECTION);
break;
@@ -831,11 +834,14 @@ static const ULONG ami_asl_mime_hook(struct Hook *mh,struct FileRequester *fr,st
return ret;
}
-void ami_menu_update_disabled(struct Window *win, hlcache_handle *c)
+void ami_menu_update_disabled(struct gui_window *g, hlcache_handle *c)
{
+ struct Window *win = g->shared->win;
+
OffMenu(win,AMI_MENU_CUT);
+ OffMenu(win,AMI_MENU_COPY);
+ OffMenu(win,AMI_MENU_PASTE);
OffMenu(win,AMI_MENU_CLEAR);
- OffMenu(win,AMI_MENU_PASTE); // c_h
if(content_get_type(c) <= CONTENT_CSS)
{
@@ -844,7 +850,15 @@ void ami_menu_update_disabled(struct Window *win, hlcache_handle *c)
#ifdef WITH_PDF_EXPORT
OnMenu(win,AMI_MENU_SAVEAS_PDF);
#endif
- OffMenu(win,AMI_MENU_COPY);
+ if(selection_defined(g->shared->bw->sel))
+ {
+ OnMenu(win,AMI_MENU_COPY);
+ OnMenu(win,AMI_MENU_CLEAR);
+
+ if(selection_read_only(g->shared->bw->sel) == false)
+ OnMenu(win,AMI_MENU_CUT);
+ }
+ if(g->c_h) OnMenu(win,AMI_MENU_PASTE);
OnMenu(win,AMI_MENU_SELECTALL);
OnMenu(win,AMI_MENU_FIND);
OffMenu(win,AMI_MENU_SAVEAS_IFF);
diff --git a/amiga/menu.h b/amiga/menu.h
index 0934a68c9..6f376d9dd 100755
--- a/amiga/menu.h
+++ b/amiga/menu.h
@@ -67,5 +67,5 @@ struct NewMenu *ami_create_menu(ULONG type);
void ami_init_menulabs(void);
void ami_free_menulabs(void);
void ami_menupick(ULONG code,struct gui_window_2 *gwin,struct MenuItem *item);
-void ami_menu_update_disabled(struct Window *win, hlcache_handle *c);
+void ami_menu_update_disabled(struct gui_window *g, hlcache_handle *c);
#endif