/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#+
#+     Internet Radio Automation & Encoding Toolkit
#+
#+     Copyright (C) 2018, 2019, 2020, 2021 by Kevin C. O'Kane
#+
#+     Kevin C. O'Kane
#+     kc.okane@gmail.com
#+     https://www.cs.uni.edu/~okane
#+     https://threadsafebooks.com/
#+
#+ This program 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; either version 2 of the License, or
#+ (at your option) any later version.
#+
#+ This program 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, write to the Free Software
#+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#+
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/

//	Oct 14, 2021

#include "includes.h"
#include "common-externs.h"

#define SLASH '/'


/* ======================================================================
        entry boxes in the edit panel

        entry1  top row result from directory
        entry7  program list row 1
        entry8  program list row 2
        entry9  program list row 3
        entry10 program list row 4
        entry11 program list row 5
        entry12 program list row 6
        entry13 program list row 7
        entry14 program list row 8
        entry2  program list row 9
        entry3  program list row 10
        entry4  program list row 11
        entry15 program list row 12
   ======================================================================*/


void    on_entry7_drag_data_get(GtkEntry *e)    {
	copyClipRow = e7Row;
	}
void    on_entry8_drag_data_get(GtkEntry *e)    {
	copyClipRow = e8Row;
	}
void    on_entry9_drag_data_get(GtkEntry *e)    {
	copyClipRow = e9Row;
	}
void    on_entry10_drag_data_get(GtkEntry *e)   {
	copyClipRow = e10Row;
	}
void    on_entry11_drag_data_get(GtkEntry *e)   {
	copyClipRow = e11Row;
	}
void    on_entry12_drag_data_get(GtkEntry *e)   {
	copyClipRow = e12Row;
	}
void    on_entry13_drag_data_get(GtkEntry *e)   {
	copyClipRow = e13Row;
	}
void    on_entry14_drag_data_get(GtkEntry *e)   {
	copyClipRow = e14Row;
	}
void    on_entry2_drag_data_get(GtkEntry *e)    {
	copyClipRow = e2Row;
	}
void    on_entry3_drag_data_get(GtkEntry *e)    {
	copyClipRow = e3Row;
	}
void    on_entry4_drag_data_get(GtkEntry *e)    {
	copyClipRow = e4Row;
	}
void    on_entry15_drag_data_get(GtkEntry *e)   {
	copyClipRow = e15Row;
	}

//--------------- DRAG DATA RECEIVED signals program rows

//------------------------------------------------------------------------
//      on_entry2_drag_data_received  on_entry3_drag_data_received
//      on_entry4_drag_data_received   on_entry7_drag_data_received
//      on_entry8_drag_data_received  on_entry9_drag_data_received
//      on_entry10_drag_data_received  on_entry11_drag_data_received
//      on_entry12_drag_data_received on_entry13_drag_data_received
//      on_entry14_drag_data_received on_entry15_drag_data_received
//------------------------------------------------------------------------

#define ENTRY_DRAG_DATA_RECEIVED(NBR) \
        void on_entry## NBR ##_drag_data_received(GtkButton  *b) { \
                if (copyClipRow >= 0 ) { paste(&e## NBR ##Row); } \
                else paste1(&e## NBR ##Row); \
                }

ENTRY_DRAG_DATA_RECEIVED(2)  ENTRY_DRAG_DATA_RECEIVED(3)  ENTRY_DRAG_DATA_RECEIVED(4)
ENTRY_DRAG_DATA_RECEIVED(7)  ENTRY_DRAG_DATA_RECEIVED(8)  ENTRY_DRAG_DATA_RECEIVED(9)
ENTRY_DRAG_DATA_RECEIVED(10) ENTRY_DRAG_DATA_RECEIVED(11) ENTRY_DRAG_DATA_RECEIVED(12)
ENTRY_DRAG_DATA_RECEIVED(13) ENTRY_DRAG_DATA_RECEIVED(14) ENTRY_DRAG_DATA_RECEIVED(15)

//--------------- TILE BUTTON DRAG/PRESS EVENT program tiles

//----------------------------------------------------------------------------------------------
//      on_p1_drag_begin on_p2_drag_begin on_p3_drag_begin on_p4_drag_begin
//      on_p5_drag_begin on_p6_drag_begin on_p7_drag_begin on_p8_drag_begin
//      on_p9_drag_begin on_p10_drag_begin on_p11_drag_begin on_p12_drag_begin
//
//      on_p1_drag_drop on_p2_drag_drop on_p3_drag_drop on_p4_drag_drop
//      on_p5_drag_drop on_p6_drag_drop on_p7_drag_drop on_p8_drag_drop
//      on_p9_drag_drop on_p10_drag_drop on_p11_drag_drop on_p12_drag_drop
//
//      on_p1_drag_data_get on_p2_drag_data_get on_p3_drag_data_get on_p4_drag_data_get
//      on_p5_drag_data_get on_p6_drag_data_get on_p7_drag_data_get on_p8_drag_data_get
//      on_p9_drag_data_get on_p10_drag_data_get on_p11_drag_data_get on_p12_drag_data_get
//
//      on_p1_drag_end on_p2_drag_end on_p3_drag_end on_p4_drag_end
//      on_p5_drag_end on_p6_drag_end on_p7_drag_end on_p8_drag_end
//      on_p9_drag_end on_p10_drag_end on_p11_drag_end on_p12_drag_end
//----------------------------------------------------------------------------------------------

#define P_BUTTON_DRAG(NBR) \
        void on_p## NBR ##_drag_begin \
                (GtkWidget *w, GdkDragContext *dc) {  \
                        drag_source =  SP->begin + NBR - 1; \
                        } \
        void on_p## NBR ##_drag_drop \
                (GtkWidget *w, GdkDragContext *dc) {  \
                        drag_target = SP->begin + NBR - 1; \
                        } \
        void on_p## NBR ##_drag_data_get \
                (GtkWidget *w, GdkDragContext *dc) {  \
                        } \
        void on_p## NBR ##_drag_end \
                (GtkWidget *w, GdkDragContext *dc) {  \
                int j = copyClipRow = drag_source ; \
                int i = drag_target; \
                if (drag_target < 0 || drag_source < 0 || i > SP->scount || j > SP->scount) { \
                drag_source = drag_target = -1; return; } \
                printf("move %d to %d\n\n", drag_source, drag_target); \
                paste(&i); if (j > i) j++; /*delRow(j);*/ \
                DisplayProgramButtons(); \
                drag_source = drag_target = -1; }


P_BUTTON_DRAG(1) P_BUTTON_DRAG(2)  P_BUTTON_DRAG(3)  P_BUTTON_DRAG(4)
P_BUTTON_DRAG(5) P_BUTTON_DRAG(6)  P_BUTTON_DRAG(7)  P_BUTTON_DRAG(8)
P_BUTTON_DRAG(9) P_BUTTON_DRAG(10) P_BUTTON_DRAG(11) P_BUTTON_DRAG(12)


//---------------------------------------------------------------------------------
//      on_p22_drag_begin    on_p23_drag_begin    on_p24_drag_begin    on_p25_drag_begin
//      on_p22_drag_drop     on_p23_drag_drop     on_p24_drag_drop     on_p25_drag_drop
//      on_p22_drag_data_get on_p23_drag_data_get on_p24_drag_data_get on_p25_drag_data_get
//      on_p22_drag_end      on_p23_drag_end      on_p24_drag_end      on_p25_drag_end
//---------------------------------------------------------------------------------

#define ALT_P_BUTTON_DRAG(NBR) \
        void on_p## NBR ##_drag_begin \
                (GtkWidget *w, GdkDragContext *dc) {  \
                        drag_source =  SP->Xbegin + NBR - 22; \
                        } \
        void on_p## NBR ##_drag_drop \
                (GtkWidget *w, GdkDragContext *dc) {  \
                        drag_target = SP->begin + NBR - 22; \
                        } \
        void on_p## NBR ##_drag_data_get \
                (GtkWidget *w, GdkDragContext *dc) {  \
                        } \
        void on_p## NBR ##_drag_end \
                (GtkWidget *w, GdkDragContext *dc) {  \
                int j = copyClipRow = drag_source ; \
                int i = drag_target; \
                if (drag_target < 0 || drag_source < 0 || i > SP->scount || j > SP->scount) { \
                drag_source = drag_target = -1; return; } \
                paste(&i); if (j > i) j++; delRow(j); \
                DisplayProgramButtons(); \
                drag_source = drag_target = -1; }

ALT_P_BUTTON_DRAG(22) ALT_P_BUTTON_DRAG(23) ALT_P_BUTTON_DRAG(24) ALT_P_BUTTON_DRAG(25)
