From c83cd8c339ecd602dfcf8dc42d15dd269a5b6ff8 Mon Sep 17 00:00:00 2001 From: Yves Rizoud Date: Thu, 12 Aug 2010 20:08:36 +0000 Subject: [PATCH] Drag and drop files: more stable. Unfinished git-svn-id: svn://pulkomandy.tk/GrafX2/trunk@1570 416bcca6-2ee7-4201-b75f-2eb2f807beb1 --- src/engine.c | 45 +++++++++++++++++++++++++++++----- src/input.c | 65 ++++++++++++++++++++++++++++++++++---------------- src/input.h | 16 +++++++++++-- src/operatio.c | 9 +++---- 4 files changed, 101 insertions(+), 34 deletions(-) diff --git a/src/engine.c b/src/engine.c index f1a86788..e1ef0a85 100644 --- a/src/engine.c +++ b/src/engine.c @@ -41,6 +41,7 @@ #include "pages.h" #include "layers.h" #include "factory.h" +#include "loadsave.h" // we need this as global @@ -658,6 +659,39 @@ void Main_handler(void) Display_all_screen(); Display_cursor(); } + else if (Drop_file_name) + { + // A file was dragged into Grafx2's window + Upload_infos_page_main(Main_backups->Pages); + + if ( (!Main_image_is_modified) || Confirmation_box("Discard unsaved changes ?") ) + { + T_IO_Context context; + char* flimit; + byte old_cursor_shape; + + flimit = Find_last_slash(Drop_file_name); + *(flimit++) = '\0'; + + Hide_cursor(); + old_cursor_shape=Cursor_shape; + Cursor_shape=CURSOR_SHAPE_HOURGLASS; + Display_cursor(); + + Init_context_layered_image(&context, flimit, Drop_file_name); + Load_image(&context); + Destroy_context(&context); + Redraw_layered_image(); + Hide_cursor(); + Cursor_shape=old_cursor_shape; + Display_cursor(); + End_of_modification(); + Display_all_screen(); + + free(Drop_file_name); + Drop_file_name=NULL; + } + } if(Get_input()) { @@ -2750,6 +2784,7 @@ short Window_get_clicked_button(void) Display_cursor(); Delay_with_active_mouse((Mouse_K==1)? Config.Delay_left_click_on_slider : Config.Delay_right_click_on_slider); Hide_cursor(); + Need_timer_for_tool=1; Window_unselect_normal_button(temp1->Pos_X,temp1->Pos_Y,temp1->Width,temp1->Height); Display_cursor(); return temp1->Number; @@ -3296,15 +3331,13 @@ void Delay_with_active_mouse(int speed) Uint32 end; end = SDL_GetTicks()+speed*10; - //Need_Timer_events=1; - //Activate_timer(10); + Need_timer_for_tool=1; do { Get_input(); now = SDL_GetTicks(); } while (nowmsg == WM_DROPFILES) { - int fileCount; + if(event.syswm.msg->msg == WM_DROPFILES) + { + int file_count; HDROP hdrop = (HDROP)(event.syswm.msg->wParam); - if((fileCount = DragQueryFile(hdrop,(UINT)-1,(LPTSTR) NULL ,(UINT) 0)) > 0) { - char buf[MAX_PATH]; - T_IO_Context context; - char* flimit; - - DragQueryFile(hdrop,0 ,(LPTSTR) buf ,(UINT) MAX_PATH); - flimit = Find_last_slash(buf); - *(flimit++) = '\0'; - - // TODO : check if there are unsaved changes first ! - - Init_context_layered_image(&context, flimit, buf); - Load_image(&context); - Destroy_context(&context); - Redraw_layered_image(); - End_of_modification(); - Display_all_screen(); + if((file_count = DragQueryFile(hdrop,(UINT)-1,(LPTSTR) NULL ,(UINT) 0)) > 0) + { + long len; + // Query filename length + len = DragQueryFile(hdrop,0 ,NULL ,0); + if (len) + { + Drop_file_name=calloc(len+1,1); + if (Drop_file_name) + { + if (DragQueryFile(hdrop,0 ,(LPTSTR) Drop_file_name ,(UINT) MAX_PATH)) + { + // Success + } + else + { + free(Drop_file_name); + // Don't report name copy error + } + } + else + { + // Don't report alloc error (for a file name? :/ ) + } + } + else + { + // Don't report weird Windows error + } + } + else + { + // Drop of zero files. Thanks for the information, Bill. } } #endif @@ -798,6 +822,7 @@ int Get_input(void) Directional_left||Directional_up_left)) { Directional_delay=-1; + Need_timer_for_cursor=1; Directional_last_move=SDL_GetTicks(); } else diff --git a/src/input.h b/src/input.h index 928a15ce..41e8e853 100644 --- a/src/input.h +++ b/src/input.h @@ -60,5 +60,17 @@ extern int Snap_axis_origin_X; /// For the :Snap_axis mode, sets the origin's point (in image coordinates) extern int Snap_axis_origin_Y; -/// Boolean, true if Push_timer_event() should put "ticks" in the SDL queue -extern volatile int Need_Timer_events; +/// +/// Boolean, true if the timer should put "ticks" in the SDL queue. +/// This one flag is for tools (airbrush) or windows (repeatable button) that require it. +extern volatile int Need_timer_for_tool; +/// +/// Boolean, true if the timer should put "ticks" in the SDL queue. +/// This one flag is for the mouse emulation, by keyboard/joystick. +extern volatile int Need_timer_for_cursor; + +/// +/// This malloced string is set when a drag-and-drop event +/// brings a file to Grafx2's window. +extern char * Drop_file_name; + \ No newline at end of file diff --git a/src/operatio.c b/src/operatio.c index 19ebcaa8..b0032bb4 100644 --- a/src/operatio.c +++ b/src/operatio.c @@ -1908,8 +1908,7 @@ void Airbrush_1_0(void) Backup(); Shade_table=Shade_table_left; - //Need_Timer_events=1; - //Activate_timer(10); + Need_timer_for_tool=1; if (SDL_GetTicks()>Airbrush_next_time) { Airbrush(LEFT_SIDE); @@ -1935,8 +1934,7 @@ void Airbrush_2_0(void) Init_start_operation(); Backup(); Shade_table=Shade_table_right; - //Need_Timer_events=1; - //Activate_timer(10); + Need_timer_for_tool=1; if (SDL_GetTicks()>Airbrush_next_time) { Airbrush(RIGHT_SIDE); @@ -1993,8 +1991,7 @@ void Airbrush_0_2(void) // { Operation_stack_size-=2; - //Need_Timer_events=0; - //Disable_timer(); + //Need_timer_for_tool=0; // Not needed, mouse release did it in Get_input() End_of_modification(); }