first version of xedittags in gtk.
authorArun Persaud <arun@nubati.net>
Sat, 17 Oct 2009 04:07:19 +0000 (21:07 -0700)
committerArun Persaud <arun@nubati.net>
Sat, 17 Oct 2009 04:07:19 +0000 (21:07 -0700)
Can't edit yet, just show the available tags.

gtk-interface.xml
interface.h
xboard.c
xedittags.c
xedittags.h

index 45d509d..7f294e2 100644 (file)
                             <property name="visible">True</property>
                             <property name="label" translatable="yes">Edit Tags</property>
                             <property name="use_underline">True</property>
+                            <signal name="activate" handler="EditTagsProc"/>
                           </object>
                         </child>
                         <child>
     <property name="stock">gtk-save</property>
     <property name="icon-size">1</property>
   </object>
+  <object class="GtkDialog" id="EditTags">
+    <property name="border_width">5</property>
+    <property name="type_hint">normal</property>
+    <property name="has_separator">False</property>
+    <child internal-child="vbox">
+      <object class="GtkVBox" id="EditTags-vbox">
+        <property name="visible">True</property>
+        <property name="orientation">vertical</property>
+        <property name="spacing">2</property>
+        <child>
+          <object class="GtkVBox" id="EditTagsTextArea">
+            <property name="visible">True</property>
+            <property name="orientation">vertical</property>
+            <child>
+              <placeholder/>
+            </child>
+          </object>
+          <packing>
+            <property name="position">1</property>
+          </packing>
+        </child>
+        <child internal-child="action_area">
+          <object class="GtkHButtonBox" id="EditTagsActionArea">
+            <property name="visible">True</property>
+            <property name="layout_style">end</property>
+            <child>
+              <object class="GtkButton" id="Edit">
+                <property name="label" translatable="yes">gtk-edit</property>
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="receives_default">True</property>
+                <property name="use_stock">True</property>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">False</property>
+                <property name="position">0</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkButton" id="Cancel">
+                <property name="label" translatable="yes">gtk-cancel</property>
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="receives_default">True</property>
+                <property name="use_stock">True</property>
+                <signal name="released" handler="EditTagsHideProc"/>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">False</property>
+                <property name="position">1</property>
+              </packing>
+            </child>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="pack_type">end</property>
+            <property name="position">0</property>
+          </packing>
+        </child>
+      </object>
+    </child>
+    <action-widgets>
+      <action-widget response="0">Edit</action-widget>
+      <action-widget response="0">Cancel</action-widget>
+    </action-widgets>
+  </object>
 </interface>
index faaa1ba..38db60d 100644 (file)
@@ -11,6 +11,8 @@ GtkWidget               *GUI_Error=NULL;
 GtkWidget               *GUI_Menubar=NULL;
 GtkWidget               *GUI_Timer=NULL;
 GtkWidget               *GUI_Buttonbar=NULL;
+GtkWidget               *GUI_EditTags=NULL;
+GtkWidget               *GUI_EditTagsTextArea=NULL;
 
 GtkListStore            *LIST_MoveHistory=NULL;
 
index 7893a4f..2a31805 100644 (file)
--- a/xboard.c
+++ b/xboard.c
@@ -635,7 +635,7 @@ MenuItem modeMenu[] = {
     {N_("Show Game List"), ShowGameListProc},
     //    {"Show Move History", HistoryShowProc}, // [HGM] hist: activate 4.2.7 code
     {"----", NothingProc},
-    {N_("Edit Tags"), EditTagsProc},
+    //    {N_("Edit Tags"), EditTagsProc},
     {N_("Edit Comment"), EditCommentProc},
     {N_("ICS Input Box"), IcsInputBoxProc},
     {NULL, NULL}
@@ -1778,7 +1778,7 @@ XtActionsRec boardActions[] = {
     { "EngineOutputProc", EngineOutputProc}, // [HGM] Winboard_x engine-output window
     { "ShowGameListProc", ShowGameListProc },
     //    { "ShowMoveListProc", HistoryShowProc},
-    { "EditTagsProc", EditCommentProc },
+    //    { "EditTagsProc", EditCommentProc },
     { "EditCommentProc", EditCommentProc },
     //    { "IcsAlarmProc", IcsAlarmProc },
     { "IcsInputBoxProc", IcsInputBoxProc },
@@ -2183,6 +2183,13 @@ main(argc, argv)
     LIST_MoveHistory = GTK_LIST_STORE (gtk_builder_get_object (builder, "MoveHistoryStore"));
     if(!LIST_MoveHistory) printf("Error: gtk_builder didn't work!\n");
 
+    /* EditTags window */
+    GUI_EditTags = GTK_WIDGET (gtk_builder_get_object (builder, "EditTags"));
+    if(!GUI_EditTags) printf("Error: gtk_builder didn't work!\n");
+    
+    GUI_EditTagsTextArea = GTK_WIDGET (gtk_builder_get_object (builder, "EditTagsTextArea"));
+    if(!GUI_EditTagsTextArea) printf("Error: gtk_builder didn't work!\n");
+
 
     gtk_builder_connect_signals (builder, NULL);
 
index 63be84e..5542d25 100644 (file)
@@ -27,6 +27,8 @@
 #include <ctype.h>
 #include <errno.h>
 #include <sys/types.h>
+#include <gtk/gtk.h>
+
 
 #if STDC_HEADERS
 # include <stdlib.h>
@@ -44,38 +46,6 @@ extern char *getenv();
 # include <unistd.h>
 #endif
 
-#include <X11/Intrinsic.h>
-#include <X11/StringDefs.h>
-#include <X11/Shell.h>
-#include <X11/cursorfont.h>
-#if USE_XAW3D
-#include <X11/Xaw3d/Dialog.h>
-#include <X11/Xaw3d/Form.h>
-#include <X11/Xaw3d/List.h>
-#include <X11/Xaw3d/Label.h>
-#include <X11/Xaw3d/SimpleMenu.h>
-#include <X11/Xaw3d/SmeBSB.h>
-#include <X11/Xaw3d/SmeLine.h>
-#include <X11/Xaw3d/Box.h>
-#include <X11/Xaw3d/MenuButton.h>
-#include <X11/Xaw3d/Text.h>
-#include <X11/Xaw3d/AsciiText.h>
-#include <X11/Xaw3d/Viewport.h>
-#else
-#include <X11/Xaw/Dialog.h>
-#include <X11/Xaw/Form.h>
-#include <X11/Xaw/List.h>
-#include <X11/Xaw/Label.h>
-#include <X11/Xaw/SimpleMenu.h>
-#include <X11/Xaw/SmeBSB.h>
-#include <X11/Xaw/SmeLine.h>
-#include <X11/Xaw/Box.h>
-#include <X11/Xaw/MenuButton.h>
-#include <X11/Xaw/Text.h>
-#include <X11/Xaw/AsciiText.h>
-#include <X11/Xaw/Viewport.h>
-#endif
-
 #include "common.h"
 #include "frontend.h"
 #include "backend.h"
@@ -83,6 +53,10 @@ extern char *getenv();
 #include "xedittags.h"
 #include "gettext.h"
 
+extern GtkWidget               *GUI_EditTags;
+extern GtkWidget               *GUI_EditTagsTextArea;
+
+
 #ifdef ENABLE_NLS
 # define  _(s) gettext (s)
 # define N_(s) gettext_noop (s)
@@ -91,332 +65,92 @@ extern char *getenv();
 # define N_(s)  s
 #endif
 
-extern Widget formWidget, shellWidget, boardWidget, menuBarWidget;
-extern Display *xDisplay;
-extern int squareSize;
-extern Pixmap xMarkPixmap;
-extern char *layoutName;
-
-Position tagsX = -1, tagsY = -1;
-int tagsUp = False, editTagsUp = False;
-Widget tagsShell, editTagsShell;
-
-static Arg layoutArgs[] = {
-    { XtNborderWidth, 0 },
-    { XtNdefaultDistance, 0 }
-};
-
-void TagsCallback(w, client_data, call_data)
-     Widget w;
-     XtPointer client_data, call_data;
-{
-    String name;
-    Arg args[16];
-    int j;
-
-    j = 0;
-    XtSetArg(args[j], XtNlabel, &name);  j++;
-    XtGetValues(w, args, j);
-
-    if (strcmp(name, _("close")) == 0) {
-       TagsPopDown();
-    } else if (strcmp(name, _("edit")) == 0) {
-       TagsPopDown();
-       EditTagsEvent();
-    }
-}
-
-
-void EditTagsCallback(w, client_data, call_data)
-     Widget w;
-     XtPointer client_data, call_data;
+void 
+TagsPopDown()
 {
-    String name, val;
-    Arg args[16];
-    int j;
-    Widget textw;
-
-    j = 0;
-    XtSetArg(args[j], XtNlabel, &name);  j++;
-    XtGetValues(w, args, j);
-
-    if (strcmp(name, _("ok")) == 0) {
-       textw = XtNameToWidget(editTagsShell, "*form.text");
-       j = 0;
-       XtSetArg(args[j], XtNstring, &val); j++;
-       XtGetValues(textw, args, j);
-       ReplaceTags(val, &gameInfo);
-       TagsPopDown();
-    } else if (strcmp(name, _("cancel")) == 0) {
-       TagsPopDown();
-    } else if (strcmp(name, _("clear")) == 0) {
-       textw = XtNameToWidget(editTagsShell, "*form.text");
-       XtCallActionProc(textw, "select-all", NULL, NULL, 0);
-       XtCallActionProc(textw, "kill-selection", NULL, NULL, 0);
-    }
-}
-
-Widget TagsCreate(name, text, msg, mutable, callback)
-     char *name, *text, *msg;
-     int /*Boolean*/ mutable;
-     XtCallbackProc callback;
-{
-    Arg args[16];
-    Widget shell, form, textw, msgw, layout;
-    Widget b_ok, b_cancel, b_close, b_edit, b;
-    Dimension bw_width, pw_width;
-    Dimension pw_height;
-    int j, xx, yy;
-    Window junk;
-
-    j = 0;
-    XtSetArg(args[j], XtNwidth, &bw_width);  j++;
-    XtGetValues(boardWidget, args, j);
-
-    j = 0;
-    XtSetArg(args[j], XtNresizable, True);  j++;
-#if TOPLEVEL
-    shell =
-      XtCreatePopupShell(name, topLevelShellWidgetClass,
-                        shellWidget, args, j);
-#else
-    shell =
-      XtCreatePopupShell(name, transientShellWidgetClass,
-                        shellWidget, args, j);
-#endif
-    layout =
-      XtCreateManagedWidget(layoutName, formWidgetClass, shell,
-                           layoutArgs, XtNumber(layoutArgs));
-    j = 0;
-    XtSetArg(args[j], XtNborderWidth, 0); j++;
-    form =
-      XtCreateManagedWidget("form", formWidgetClass, layout, args, j);
-
-    j = 0;
-    if (mutable) {
-       XtSetArg(args[j], XtNeditType, XawtextEdit);  j++;
-       XtSetArg(args[j], XtNuseStringInPlace, False);  j++;
-    }
-    XtSetArg(args[j], XtNstring, text);  j++;
-    XtSetArg(args[j], XtNtop, XtChainTop);  j++;
-    XtSetArg(args[j], XtNbottom, XtChainBottom);  j++;
-    XtSetArg(args[j], XtNleft, XtChainLeft);  j++;
-    XtSetArg(args[j], XtNright, XtRubber);  j++;
-    XtSetArg(args[j], XtNresizable, True);  j++;
-    XtSetArg(args[j], XtNwidth, bw_width/2);  j++;
-    XtSetArg(args[j], XtNheight, bw_width/3);  j++;
-    /* !!Work around an apparent bug in XFree86 4.0.1 (X11R6.4.3) */
-    XtSetArg(args[j], XtNscrollVertical, XawtextScrollAlways);  j++;
-    XtSetArg(args[j], XtNautoFill, False);  j++;
-    textw =
-      XtCreateManagedWidget("text", asciiTextWidgetClass, form, args, j);
-
-    if (cmailMsgLoaded && !mutable) {
-       j = 0;
-       XtSetArg(args[j], XtNfromVert, textw);  j++;
-       XtSetArg(args[j], XtNtop, XtChainBottom); j++;
-       XtSetArg(args[j], XtNbottom, XtChainBottom); j++;
-       XtSetArg(args[j], XtNleft, XtChainLeft); j++;
-       XtSetArg(args[j], XtNright, XtChainRight); j++;
-       XtSetArg(args[j], XtNborderWidth, 0); j++;
-       XtSetArg(args[j], XtNjustify, XtJustifyLeft); j++;
-       XtSetArg(args[j], XtNlabel, msg); j++;
-       msgw =
-         XtCreateManagedWidget("msg", labelWidgetClass, form, args, j);
-    } else {
-       msgw = textw;
-    }
-    if (mutable) {
-       j = 0;
-       XtSetArg(args[j], XtNfromVert, msgw);  j++;
-       XtSetArg(args[j], XtNtop, XtChainBottom); j++;
-       XtSetArg(args[j], XtNbottom, XtChainBottom); j++;
-       XtSetArg(args[j], XtNleft, XtChainLeft); j++;
-       XtSetArg(args[j], XtNright, XtChainLeft); j++;
-       b_ok = b =
-         XtCreateManagedWidget(_("ok"), commandWidgetClass, form, args, j);
-       XtAddCallback(b_ok, XtNcallback, callback, (XtPointer) 0);
-
-       j = 0;
-       XtSetArg(args[j], XtNfromVert, msgw);  j++;
-       XtSetArg(args[j], XtNfromHoriz, b);  j++;
-       XtSetArg(args[j], XtNtop, XtChainBottom); j++;
-       XtSetArg(args[j], XtNbottom, XtChainBottom); j++;
-       XtSetArg(args[j], XtNleft, XtChainLeft); j++;
-       XtSetArg(args[j], XtNright, XtChainLeft); j++;
-       b_cancel = b =
-         XtCreateManagedWidget(_("cancel"), commandWidgetClass, form, args, j);
-       XtAddCallback(b_cancel, XtNcallback, callback, (XtPointer) 0);
-
-    } else {
-       j = 0;
-       XtSetArg(args[j], XtNfromVert, msgw);  j++;
-       XtSetArg(args[j], XtNtop, XtChainBottom); j++;
-       XtSetArg(args[j], XtNbottom, XtChainBottom); j++;
-       XtSetArg(args[j], XtNleft, XtChainLeft); j++;
-       XtSetArg(args[j], XtNright, XtChainLeft); j++;
-       b_close = b =
-         XtCreateManagedWidget(_("close"), commandWidgetClass, form, args, j);
-       XtAddCallback(b_close, XtNcallback, callback, (XtPointer) 0);
-
-       j = 0;
-       XtSetArg(args[j], XtNfromVert, msgw);  j++;
-       XtSetArg(args[j], XtNfromHoriz, b);  j++;
-       XtSetArg(args[j], XtNtop, XtChainBottom); j++;
-       XtSetArg(args[j], XtNbottom, XtChainBottom); j++;
-       XtSetArg(args[j], XtNleft, XtChainLeft); j++;
-       XtSetArg(args[j], XtNright, XtChainLeft); j++;
-       b_edit = b =
-         XtCreateManagedWidget(_("edit"), commandWidgetClass, form, args, j);
-       XtAddCallback(b_edit, XtNcallback, callback, (XtPointer) 0);
-    }
-
-    XtRealizeWidget(shell);
-    CatchDeleteWindow(shell, "TagsPopDown");
-
-    if (tagsX == -1) {
-       j = 0;
-       XtSetArg(args[j], XtNwidth, &bw_width);  j++;
-       XtGetValues(boardWidget, args, j);
-       j = 0;
-       XtSetArg(args[j], XtNwidth, &pw_width);  j++;
-       XtSetArg(args[j], XtNheight, &pw_height);  j++;
-       XtGetValues(shell, args, j);
-
-#ifdef NOTDEF
-       /* This code seems to tickle an X bug if it is executed too soon
-          after xboard starts up.  The coordinates get transformed as if
-          the main window was positioned at (0, 0).
-          */
-       XtTranslateCoords(boardWidget, (bw_width - pw_width) / 2,
-                         0 - pw_height + squareSize / 3, &x, &y);
-#else
-       XTranslateCoordinates(xDisplay, XtWindow(boardWidget),
-                             RootWindowOfScreen(XtScreen(boardWidget)),
-                             (bw_width - pw_width) / 2,
-                             0 - pw_height + squareSize / 3, &xx, &yy, &junk);
-       tagsX = xx;
-       tagsY = yy;
-#endif
-       if (tagsY < 0) tagsY = 0; /*avoid positioning top offscreen*/
-    }
-    j = 0;
-    XtSetArg(args[j], XtNx, tagsX - appData.borderXoffset);  j++;
-    XtSetArg(args[j], XtNy, tagsY - appData.borderYoffset);  j++;
-    XtSetValues(shell, args, j);
-    XtSetKeyboardFocus(shell, textw);
-
-    return shell;
+  return;
 }
 
-
-void TagsPopUp(tags, msg)
-     char *tags, *msg;
+void 
+TagsPopUp(char *tags, char *msg)
 {
-    Arg args[16];
-    int j;
-    Widget textw, msgw;
-
-    if (editTagsUp) TagsPopDown();
-    if (tagsShell == NULL) {
-       tagsShell =
-         TagsCreate(_("Tags"), tags, msg, False, TagsCallback);
-    } else {
-       textw = XtNameToWidget(tagsShell, "*form.text");
-       j = 0;
-       XtSetArg(args[j], XtNstring, tags); j++;
-       XtSetValues(textw, args, j);
-       j = 0;
-       XtSetArg(args[j], XtNiconName, (XtArgVal) "Tags");  j++;
-       XtSetArg(args[j], XtNtitle, (XtArgVal) _("Tags"));  j++;
-       XtSetValues(tagsShell, args, j);
-       msgw = XtNameToWidget(tagsShell, "*form.msg");
-       if (msgw) {
-           j = 0;
-           XtSetArg(args[j], XtNlabel, msg); j++;
-           XtSetValues(msgw, args, j);
-       }
-    }
-
-    XtPopup(tagsShell, XtGrabNone);
-    XSync(xDisplay, False);
-
-    tagsUp = True;
-    j = 0;
-    XtSetArg(args[j], XtNleftBitmap, None); j++;
-    XtSetValues(XtNameToWidget(menuBarWidget, "menuMode.Edit Tags"),
-               args, j);
+  EditTagsPopUp(tags);
+  return;
 }
 
 
-void EditTagsPopUp(tags)
+//void EditTagsCallback(w, client_data, call_data)
+//     Widget w;
+//     XtPointer client_data, call_data;
+//{
+//    String name, val;
+//    Arg args[16];
+//    int j;
+//    Widget textw;
+//
+//    j = 0;
+//    XtSetArg(args[j], XtNlabel, &name);  j++;
+//    XtGetValues(w, args, j);
+//    
+//
+//    if (strcmp(name, _("ok")) == 0) {
+//    /* ok: get values, update, close */
+//     textw = XtNameToWidget(editTagsShell, "*form.text");
+//     j = 0;
+//     XtSetArg(args[j], XtNstring, &val); j++;
+//     XtGetValues(textw, args, j);
+//     ReplaceTags(val, &gameInfo);
+//     TagsPopDown();
+//    } else if (strcmp(name, _("cancel")) == 0) {
+//      /* close */
+//     TagsPopDown();
+//    } else if (strcmp(name, _("clear")) == 0) {
+//      /* clear all */
+//     textw = XtNameToWidget(editTagsShell, "*form.text");
+//     XtCallActionProc(textw, "select-all", NULL, NULL, 0);
+//     XtCallActionProc(textw, "kill-selection", NULL, NULL, 0);
+//    }
+//}
+
+
+void 
+EditTagsPopUp(tags)
      char *tags;
 {
-    Widget textw;
-    Arg args[16];
-    int j;
-
-    if (tagsUp) TagsPopDown();
-    if (editTagsShell == NULL) {
-       editTagsShell =
-         TagsCreate(_("Edit tags"), tags, NULL, True, EditTagsCallback); 
-    } else {
-       textw = XtNameToWidget(editTagsShell, "*form.text");
-       j = 0;
-       XtSetArg(args[j], XtNstring, tags); j++;
-       XtSetValues(textw, args, j);
-       j = 0;
-       XtSetArg(args[j], XtNiconName, (XtArgVal) "Edit Tags");  j++;
-       XtSetArg(args[j], XtNtitle, (XtArgVal) _("Edit Tags"));  j++;
-       XtSetValues(editTagsShell, args, j);
-    }
-
-    XtPopup(editTagsShell, XtGrabNone);
-
-    editTagsUp = True;
-    j = 0;
-    XtSetArg(args[j], XtNleftBitmap, xMarkPixmap); j++;
-    XtSetValues(XtNameToWidget(menuBarWidget, "menuMode.Edit Tags"),
-               args, j);
+  GtkWidget *label;  
+  
+  /* add the text to the dialog */
+  
+  label = gtk_label_new (tags);
+
+  /* remove old tags that we already added */
+  gtk_container_foreach(GTK_CONTAINER (GUI_EditTagsTextArea),G_CALLBACK (gtk_widget_destroy),NULL);
+  
+  /* TODO replace this with a version where you can edit and a callback for the edit button that saves the new tags*/
+  gtk_container_add (GTK_CONTAINER (GUI_EditTagsTextArea), label);
+  
+  /* realize widget */
+  gtk_widget_show_all (GUI_EditTags);
+
+  return;
 }
 
-void TagsPopDown()
+void
+EditTagsProc(object, user_data)
+     GtkObject *object;
+     gpointer user_data;
 {
-    Arg args[16];
-    int j;
-    Widget w;
-
-    if (tagsUp) {
-       w = tagsShell;
-    } else if (editTagsUp) {
-       w = editTagsShell;
-    } else {
-       return;
-    }
-    j = 0;
-    XtSetArg(args[j], XtNx, &tagsX); j++;
-    XtSetArg(args[j], XtNy, &tagsY); j++;
-    XtGetValues(w, args, j);
-    XtPopdown(w);
-    XSync(xDisplay, False);
-    tagsUp = editTagsUp = False;
-    j = 0;
-    XtSetArg(args[j], XtNleftBitmap, None); j++;
-    XtSetValues(XtNameToWidget(menuBarWidget, "menuMode.Edit Tags"),
-               args, j);
+  /* always call EditTagsEvent, which calls the function to popup the window */
+  EditTagsEvent();
+  return;
 }
 
 void
-EditTagsProc(w, event, prms, nprms)
-     Widget w;
-     XEvent *event;
-     String *prms;
-     Cardinal *nprms;
+EditTagsHideProc(object, user_data)
+     GtkObject *object;
+     gpointer user_data;
 {
-    if (tagsUp) TagsPopDown();
-    if (editTagsUp) {
-       TagsPopDown();
-    } else {
-       EditTagsEvent();
-    }
+  /* hide everything */
+  gtk_widget_hide_all(GUI_EditTags);
+  return;
 }
index e777067..e27da9e 100644 (file)
@@ -24,7 +24,7 @@
 #ifndef _XEDITTAGS_H
 #define _XEDITTAGS_H 1
 
-void EditTagsProc P((Widget w, XEvent *event,
-                    String *prms, Cardinal *nprms));
+void EditTagsProc P((GtkObject *object, gpointer user_data));
+void EditTagsHideProc P((GtkObject *object, gpointer user_data));
 
 #endif