Fix clock clicking with GtkEventBox
[xboard.git] / gtk / xoptions.c
index 877bf02..5f4711f 100644 (file)
@@ -566,8 +566,6 @@ MemoEvent(GtkWidget *widget, GdkEvent *event, gpointer gdata)
     gboolean res;
     gint index, x, y;
 
-    if(memo->type == Label) { ((ButtonCallback*) memo->target)(memo->value); return TRUE; } // only clock widgets use this
-
     switch(event->type) { // figure out what's up
        case GDK_MOTION_NOTIFY:
            f = 0;
@@ -583,6 +581,10 @@ MemoEvent(GtkWidget *widget, GdkEvent *event, gpointer gdata)
            button = bevent->button;
            shiftState = bevent->state & GDK_SHIFT_MASK;
            controlState = bevent->state & GDK_CONTROL_MASK;
+           if(memo->type == Label) { // only clock widgets use this
+               ((ButtonCallback*) memo->target)(button == 1 ? memo->value : -memo->value);
+               return TRUE;
+           }
 // GTK_TODO: is this really the most efficient way to get the character at the mouse cursor???
            gtk_text_view_window_to_buffer_coords(GTK_TEXT_VIEW(widget), GTK_TEXT_WINDOW_WIDGET, w, h, &x, &y);
            gtk_text_view_get_iter_at_location(GTK_TEXT_VIEW(widget), &start, x, y);
@@ -634,7 +636,7 @@ GtkWidget *shells[NrOfDialogs];
 DialogClass parents[NrOfDialogs];
 WindowPlacement *wp[NrOfDialogs] = { // Beware! Order must correspond to DialogClass enum
     NULL, &wpComment, &wpTags, NULL, NULL, NULL, NULL, &wpMoveHistory, &wpGameList, &wpEngineOutput, &wpEvalGraph,
-    NULL, NULL, NULL, NULL, /*&wpMain*/ NULL
+    NULL, NULL, NULL, NULL, &wpMain
 };
 
 int
@@ -679,21 +681,9 @@ PopDown (DialogClass n)
     //Arg args[10];    
     
     if (!shellUp[n] || !shells[n]) return 0;    
-#ifdef TODO_GTK
-// Not sure this is still used
     if(n && wp[n]) { // remember position
-       j = 0;
-       XtSetArg(args[j], XtNx, &windowX); j++;
-       XtSetArg(args[j], XtNy, &windowY); j++;
-       XtSetArg(args[j], XtNheight, &windowH); j++;
-       XtSetArg(args[j], XtNwidth, &windowW); j++;
-       XtGetValues(shells[n], args, j);
-       wp[n]->x = windowX;
-       wp[n]->x = windowY;
-       wp[n]->width  = windowW;
-       wp[n]->height = windowH;
+       GetActualPlacement(shells[n], wp[n]);
     }
-#endif
     
     gtk_widget_hide(shells[n]);
     shellUp[n]--; // count rather than clear
@@ -1070,7 +1060,7 @@ static int
 SameRow (Option *opt)
 {
     return (opt->min & SAME_ROW && (opt->type == Button || opt->type == SaveButton || opt->type == Label
-                                || opt->type == ListBox || opt->type == BoxBegin || opt->type == Icon));
+                                || opt->type == ListBox || opt->type == BoxBegin || opt->type == Icon || opt->type == Graph));
 }
 
 static void
@@ -1186,7 +1176,7 @@ printf("n=%d, h=%d, w=%d\n",n,height,width);
            if(SameRow(&option[i+1])) {
                GtkAttachOptions x = GTK_FILL;
                // make sure hbox is always available when we have more options on same row
-                hbox = gtk_hbox_new (option[i].type == Button && option[i].textValue, 0);
+                hbox = gtk_hbox_new (option[i].type == Button && option[i].textValue || option[i].type == Graph, 0);
                if(!currentCps && option[i].value > 80) x |= GTK_EXPAND; // only vertically extended widgets should size vertically
                 if (strcmp(option[i].name, "") == 0 || option[i].type == Label || option[i].type == Button)
                     // for Label and Button name is contained inside option
@@ -1310,11 +1300,15 @@ printf("n=%d, h=%d, w=%d\n",n,height,width);
                label = frame;
            }
             gtk_widget_set_size_request(label, option[i].max ? option[i].max : -1, -1);
-            Pack(hbox, table, label, left, left+2, top, 0);
            if(option[i].target) { // allow user to specify event handler for button presses
+               button = gtk_event_box_new();
+                gtk_container_add(GTK_CONTAINER(button), label);
+               label = button;
                gtk_widget_add_events(GTK_WIDGET(label), GDK_BUTTON_PRESS_MASK);
                g_signal_connect(label, "button-press-event", G_CALLBACK(MemoEvent), (gpointer) &option[i]);
+               gtk_widget_set_sensitive(label, TRUE);
            }
+            Pack(hbox, table, label, left, left+2, top, 0);
            break;
           case SaveButton:
           case Button:
@@ -1415,9 +1409,9 @@ printf("n=%d, h=%d, w=%d\n",n,height,width);
             g_signal_connect (graph, "button-press-event", G_CALLBACK (GraphEventProc), (gpointer) &option[i]);
             g_signal_connect (graph, "button-release-event", G_CALLBACK (GraphEventProc), (gpointer) &option[i]);
             g_signal_connect (graph, "motion-notify-event", G_CALLBACK (GraphEventProc), (gpointer) &option[i]);
-           if(0) {
-               GtkWidget *frame = gtk_aspect_frame_new(NULL, 0, 0, 1, FALSE);
-//             gtk_frame_set_shadow_type(frame, GTK_SHADOW_NONE);
+           if(option[i].min & FIX_H) { // logo
+               GtkWidget *frame = gtk_aspect_frame_new(NULL, 0.5, 0.5, option[i].max/(float)option[i].value, FALSE);
+               gtk_frame_set_shadow_type(GTK_FRAME(frame), GTK_SHADOW_NONE);
                 gtk_container_add(GTK_CONTAINER(frame), graph);
                graph = frame;
            }
@@ -1493,6 +1487,7 @@ printf("n=%d, h=%d, w=%d\n",n,height,width);
 
     option[i].handle = (void *) table; // remember last table in EndMark handle (for hiding Engine-Output pane).
 
+    gtk_window_set_position(GTK_WINDOW(dialog), GTK_WIN_POS_NONE);
     /* Show dialog */
     gtk_widget_show_all( dialog );    
 
@@ -1510,6 +1505,13 @@ printf("n=%d, h=%d, w=%d\n",n,height,width);
                       (gpointer)(intptr_t) dlgNr);
     shellUp[dlgNr]++;
 
+    if(dlgNr && wp[dlgNr] && wp[dlgNr]->width > 0) { // if persistent window-info available, reposition
+       gtk_window_move(GTK_WINDOW(dialog), wp[dlgNr]->x, wp[dlgNr]->y);
+//printf("moved %d to (%d,%d)\n", dlgNr, wp[dlgNr]->x, wp[dlgNr]->y);
+       gtk_window_resize(GTK_WINDOW(dialog), wp[dlgNr]->width, wp[dlgNr]->height);
+//printf("resized %d to %dx%d\n", dlgNr, wp[dlgNr]->width, wp[dlgNr]->height);
+    }
+
     return 1; // tells caller he must do initialization (e.g. add specific event handlers)
 }