"Fossies" - the Fresh Open Source Software Archive

Member "gambas-3.16.3/gb.gtk/src/gsignals.cpp" (7 Sep 2021, 10294 Bytes) of package /linux/misc/gambas-3.16.3.tar.bz2:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "gsignals.cpp" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 3.16.2_vs_3.16.3.

    1 /***************************************************************************
    2 
    3   gsignals.cpp
    4 
    5   (c) 2004-2006 - Daniel Campos Fernández <dcamposf@gmail.com>
    6 
    7   This program is free software; you can redistribute it and/or modify
    8   it under the terms of the GNU General Public License as published by
    9   the Free Software Foundation; either version 2, or (at your option)
   10   any later version.
   11 
   12   This program is distributed in the hope that it will be useful,
   13   but WITHOUT ANY WARRANTY; without even the implied warranty of
   14   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   15   GNU General Public License for more details.
   16 
   17   You should have received a copy of the GNU General Public License
   18   along with this program; if not, write to the Free Software
   19   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
   20   MA 02110-1301, USA.
   21 
   22 ***************************************************************************/
   23 
   24 #include "widgets.h"
   25 #include <gdk/gdkkeysyms.h>
   26 
   27 #include "gapplication.h"
   28 #include "gdrawingarea.h"
   29 #include "gkey.h"
   30 #include "gmouse.h"
   31 #include "gmainwindow.h"
   32 #include "gdrag.h"
   33 #include "gdesktop.h"
   34 
   35 //#define DEBUG_DND 1
   36 
   37 static void cb_destroy(GtkWidget *object, gControl *data)
   38 {
   39     if (data->_no_delete)
   40         return;
   41         
   42     //if (!data->_destroyed)
   43     delete data;
   44 }
   45 
   46 static gboolean cb_menu(GtkWidget *widget, gControl *data)
   47 {
   48     if (data->onMouseEvent)
   49         return data->onMouseEvent(data, gEvent_MouseMenu);
   50     else
   51         return false;
   52 }
   53 
   54 gboolean gcb_focus_in(GtkWidget *widget, GdkEventFocus *event, gControl *data)
   55 {
   56     //fprintf(stderr, "gcb_focus_in: %s\n", data->name());
   57     
   58     gApplication::setActiveControl(data, true);
   59     if (data->frame)
   60         data->refresh();
   61 
   62     return false;
   63 }
   64 
   65 gboolean gcb_focus_out(GtkWidget *widget, GdkEventFocus *event, gControl *data)
   66 {   
   67     //fprintf(stderr, "gcb_focus_out: %s\n", data->name());
   68     
   69     /*if (!::strcmp(data->name(), "txtName"))
   70         BREAKPOINT();*/
   71 
   72     if (!gApplication::_keep_focus)
   73         gApplication::setActiveControl(data, false);
   74     if (data->frame)
   75         data->refresh();
   76     
   77     return false;
   78 }
   79 
   80 gboolean gcb_focus(GtkWidget *widget, GtkDirectionType direction, gControl *data)
   81 {
   82     gControl *ctrl;
   83     
   84     if (direction == GTK_DIR_TAB_FORWARD || direction == GTK_DIR_TAB_BACKWARD)
   85     {
   86         ctrl = gApplication::activeControl();
   87 
   88         if (!ctrl)
   89             return true;
   90         
   91         if (ctrl->topLevel() != data)
   92             return true;
   93         
   94         for(;;)
   95         {
   96             if (direction == GTK_DIR_TAB_FORWARD)
   97                 ctrl = ctrl->nextFocus();
   98             else
   99                 ctrl = ctrl->previousFocus();
  100             
  101             if (!ctrl)
  102                 break;
  103             
  104             if (ctrl->isReallyVisible() && ctrl->isEnabled() && ctrl->canFocus() && !ctrl->isNoTabFocus())
  105             {
  106                 //fprintf(stderr, "cb_focus: --> %s\n", ctrl->name());
  107                 ctrl->setFocus();
  108                 break;
  109             }
  110             if (ctrl == data)
  111                 break;
  112         }
  113     }
  114 
  115     return true;
  116 }
  117 
  118 
  119 /****************************************************
  120  Drag 
  121 *****************************************************/
  122 
  123 static void cb_drag_data_get(GtkWidget *widget, GdkDragContext *context, GtkSelectionData *dt, guint i, guint time, gControl *data)
  124 {
  125     char *text;
  126     int len;
  127     gPicture *pic;
  128     //g_debug("sg_drag_data_get\n");
  129     
  130     context = gDrag::enable(context, data, time);
  131     
  132     text = gDrag::getText(&len, NULL, true);
  133     if (text)
  134     {
  135         gtk_selection_data_set_text(dt, text, len);
  136         return;
  137     }
  138     
  139     pic = gDrag::getImage(true);
  140     if (pic)
  141     {
  142         gtk_selection_data_set_pixbuf(dt, pic->getPixbuf());
  143     }
  144     
  145     gDrag::disable(context);
  146 }
  147 
  148 static void cb_drag_end(GtkWidget *widget,GdkDragContext *ct,gControl *data)
  149 {
  150     #if DEBUG_DND
  151     fprintf(stderr, "sg_drag_end: %s\n", data->name());
  152     #endif
  153     
  154     gDrag::end();
  155 }
  156 
  157 
  158 /****************************************************
  159  Drop 
  160 *****************************************************/
  161 
  162 // BM: What for?
  163 //static guint32 _drag_time = 0;
  164 
  165 static void cb_drag_leave(GtkWidget *widget, GdkDragContext *context, guint time, gControl *data)
  166 {
  167     if (!gDrag::isCurrent(data))
  168         return;
  169     
  170     #if DEBUG_DND
  171     fprintf(stderr, "cb_drag_leave: %s\n", data->name());
  172     #endif
  173 
  174     gDrag::setCurrent(NULL);
  175     gDrag::hide(data);
  176 }
  177 
  178 static gboolean cb_drag_motion(GtkWidget *widget, GdkDragContext *context, gint x, gint y, guint time, gControl *data)
  179 {
  180     bool retval = true;
  181     int action;
  182     gControl *source;
  183     
  184     #if DEBUG_DND
  185     fprintf(stderr, "cb_drag_motion: %s\n", data->name());
  186     #endif  
  187     
  188     gApplication::checkHoveredControl(data);
  189     
  190     /*if (_drag_time != context->start_time) 
  191     { 
  192         g_debug("cb_drag_motion: cancel!\n");
  193         gDrag::cancel();
  194         data->_drop_0 = true; 
  195         data->_drop_1 = false; 
  196         data->_drop_2 = false; 
  197     }*/
  198     
  199 #if GTK_CHECK_VERSION(2, 22, 0)
  200     switch (gdk_drag_context_get_suggested_action(context))
  201 #else
  202     switch (context->suggested_action)
  203 #endif
  204     {
  205     case GDK_ACTION_MOVE: 
  206         action = gDrag::Move; 
  207         break;
  208     case GDK_ACTION_LINK: 
  209         action = gDrag::Link; 
  210         break;
  211         case GDK_ACTION_COPY:
  212         default:
  213             action = gDrag::Copy;
  214     }
  215     
  216     source = gApplication::controlItem(gtk_drag_get_source_widget(context));
  217     gDrag::setDropData(action, x, y, source, NULL);
  218     
  219     context = gDrag::enable(context, data, time);
  220     
  221     retval = gDrag::setCurrent(data);
  222     
  223     if (retval)
  224     {
  225         //fprintf(stderr, "cb_drag_motion: onDragMove: %p\n", widget);
  226         gControl *control = data;
  227         
  228         //while (control->_proxy)
  229         //  control = control->_proxy;
  230         
  231         while (control)
  232         {
  233             #if DEBUG_DND
  234             fprintf(stderr, "send DragMove %s\n", control->name());
  235             #endif
  236             if (control->canRaise(control, gEvent_DragMove))
  237             {
  238                 if (control->onDragMove) 
  239                 {
  240                     retval = !control->onDragMove(control);
  241                     if (!retval)
  242                         break;
  243                 }
  244             }
  245             control = control->_proxy;
  246         }
  247     }
  248     
  249     context = gDrag::disable(context);
  250     
  251     if (retval) 
  252     {
  253         #if DEBUG_DND
  254         fprintf(stderr, "cb_drag_motion: accept\n");
  255         #endif
  256 #if GTK_CHECK_VERSION(2, 22, 0)
  257         gdk_drag_status(context, gdk_drag_context_get_suggested_action(context), time);
  258 #else
  259         gdk_drag_status(context, context->suggested_action, time);
  260 #endif
  261         return true;
  262     }
  263     
  264     #if DEBUG_DND
  265     fprintf(stderr, "cb_drag_motion: cancel\n");
  266     #endif
  267     gDrag::hide(data);
  268     return false;
  269 }
  270 
  271 
  272 static gboolean cb_drag_drop(GtkWidget *widget, GdkDragContext *context, gint x, gint y, guint time, gControl *data)
  273 {
  274     gControl *source;
  275 
  276     #if DEBUG_DND
  277     fprintf(stderr, "cb_drag_drop: %s\n", data->name());
  278     #endif
  279     
  280     /*if (!gDrag::isCurrent(data))
  281         return false;*/
  282     
  283     // cb_drag_leave() is automatically called when a drop occurs
  284     //cb_drag_leave(widget, context, time, data);
  285     
  286     if (!data->canRaise(data, gEvent_Drop))
  287     {
  288         gtk_drag_finish(context, false, false, time);
  289         return false;
  290     }
  291 
  292     source = gApplication::controlItem(gtk_drag_get_source_widget(context));
  293 
  294     gDrag::setDropData(gDrag::getAction(), x, y, source, data);
  295     
  296     context = gDrag::enable(context, data, time);
  297     data->_drag_get_data = true;
  298     
  299     if (data->onDrop)
  300         data->onDrop(data);
  301     
  302     context = gDrag::disable(context);
  303 
  304     //fprintf(stderr, "cancel = %d\n", cancel);
  305     
  306     gtk_drag_finish(context, true, false, time);
  307     
  308     //data->_drag_enter = false;
  309     data->_drag_get_data = false;
  310 
  311     return true;
  312 }
  313 
  314 // void sg_size(GtkWidget *widget,GtkRequisition *req, gContainer *data)
  315 // {
  316 //  if (data->parent()) data->parent()->performArrange();
  317 //  if (data->isContainer()) data->performArrange();
  318 // }
  319 
  320 static void cb_show(GtkWidget *widget, gContainer *data)
  321 {
  322     data->performArrange();
  323 }
  324 
  325 void gControl::borderSignals()
  326 {   
  327     g_signal_connect_after(G_OBJECT(border), "destroy", G_CALLBACK(cb_destroy), (gpointer)this);
  328     //g_signal_connect(G_OBJECT(border),"drag-data-received",G_CALLBACK(sg_drag_data_received),(gpointer)this);
  329     g_signal_connect(G_OBJECT(border), "drag-motion", G_CALLBACK(cb_drag_motion),(gpointer)this);
  330     g_signal_connect(G_OBJECT(border), "drag-leave", G_CALLBACK(cb_drag_leave),(gpointer)this);
  331     g_signal_connect(G_OBJECT(border), "drag-drop", G_CALLBACK(cb_drag_drop),(gpointer)this);
  332     g_signal_connect(G_OBJECT(border), "drag-data-get", G_CALLBACK(cb_drag_data_get),(gpointer)this);
  333     g_signal_connect(G_OBJECT(border), "drag-end", G_CALLBACK(cb_drag_end),(gpointer)this);
  334     //g_signal_connect(G_OBJECT(border),"enter-notify-event",G_CALLBACK(sg_enter),(gpointer)this);
  335     //g_signal_connect(G_OBJECT(border),"leave-notify-event",G_CALLBACK(sg_enter),(gpointer)this);
  336     
  337     //g_signal_connect_after(G_OBJECT(border),"size-allocate",G_CALLBACK(sg_size),(gpointer)this);
  338     
  339     if (isContainer())
  340         g_signal_connect(G_OBJECT(border), "show", G_CALLBACK(cb_show), (gpointer)this);
  341 
  342     if (border != widget && !_scroll)
  343     {
  344         /*if (!_no_default_mouse_event)
  345         {
  346             g_signal_connect(G_OBJECT(border),"button-release-event",G_CALLBACK(gcb_button_release),(gpointer)this);
  347             g_signal_connect(G_OBJECT(border),"button-press-event",G_CALLBACK(gcb_button_press),(gpointer)this);
  348         }*/
  349         g_signal_connect(G_OBJECT(border), "popup-menu", G_CALLBACK(cb_menu), (gpointer)this);  
  350         //g_signal_connect_after(G_OBJECT(border),"motion-notify-event",G_CALLBACK(sg_motion),(gpointer)this);
  351         //g_signal_connect(G_OBJECT(border),"scroll-event",G_CALLBACK(sg_scroll),(gpointer)this);
  352     }
  353 }
  354 
  355 void gControl::widgetSignals()
  356 {
  357     if (!(border != widget && !_scroll))
  358     {
  359         //g_signal_connect(G_OBJECT(widget),"scroll-event",G_CALLBACK(sg_scroll),(gpointer)this);
  360         /*if (!_no_default_mouse_event)
  361         {
  362             g_signal_connect(G_OBJECT(widget),"button-release-event",G_CALLBACK(gcb_button_release),(gpointer)this);
  363             g_signal_connect(G_OBJECT(widget),"button-press-event",G_CALLBACK(gcb_button_press),(gpointer)this);
  364         }*/
  365         //g_signal_connect(G_OBJECT(widget),"motion-notify-event",G_CALLBACK(sg_motion),(gpointer)this);
  366         g_signal_connect(G_OBJECT(widget), "popup-menu", G_CALLBACK(cb_menu), (gpointer)this);
  367     }   
  368     
  369     g_signal_connect(G_OBJECT(widget), "key-press-event", G_CALLBACK(gcb_key_event), (gpointer)this);
  370     g_signal_connect(G_OBJECT(widget), "key-release-event", G_CALLBACK(gcb_key_event), (gpointer)this);
  371     g_signal_connect(G_OBJECT(widget), "focus", G_CALLBACK(gcb_focus), (gpointer)this);
  372     g_signal_connect(G_OBJECT(widget), "focus-in-event", G_CALLBACK(gcb_focus_in), (gpointer)this);
  373     g_signal_connect(G_OBJECT(widget), "focus-out-event", G_CALLBACK(gcb_focus_out), (gpointer)this);
  374     //g_signal_connect(G_OBJECT(widget),"event",G_CALLBACK(sg_event),(gpointer)this);
  375     if (widget != border)
  376     {
  377         g_signal_connect(G_OBJECT(widget), "drag-end", G_CALLBACK(cb_drag_end), (gpointer)this);
  378     }
  379 }
  380 
  381 void gControl::initSignals()
  382 {   
  383     borderSignals();
  384     widgetSignals();
  385 }
  386