Mercurial > hg > xemacs-beta
annotate etc/tests/external-widget/test-ew-motif.c @ 5918:cb65bfaf7110 default
Speed up XEmacs on X.
Avoid many calls to XQueryColor.
| author | Mike Sperber <sperber@deinprogramm.de> |
|---|---|
| date | Fri, 27 Mar 2015 16:05:15 +0100 |
| parents | 6a8c6c6f6c8e |
| children |
| rev | line source |
|---|---|
|
4894
03ab78e48ef6
Add copyright and license information based on Ben's recollections.
Jerry James <james@xemacs.org>
parents:
2
diff
changeset
|
1 /* Test external widget code in Motif. |
|
03ab78e48ef6
Add copyright and license information based on Ben's recollections.
Jerry James <james@xemacs.org>
parents:
2
diff
changeset
|
2 Copyright (C) 1993 Ben Wing. |
|
03ab78e48ef6
Add copyright and license information based on Ben's recollections.
Jerry James <james@xemacs.org>
parents:
2
diff
changeset
|
3 |
|
03ab78e48ef6
Add copyright and license information based on Ben's recollections.
Jerry James <james@xemacs.org>
parents:
2
diff
changeset
|
4 This file is part of XEmacs. |
|
03ab78e48ef6
Add copyright and license information based on Ben's recollections.
Jerry James <james@xemacs.org>
parents:
2
diff
changeset
|
5 |
|
5412
6a8c6c6f6c8e
Convert to GPLv3 or later from plain text GPLv2 or later.
Mats Lidell <matsl@xemacs.org>
parents:
5231
diff
changeset
|
6 XEmacs is free software: you can redistribute it and/or modify it |
|
4894
03ab78e48ef6
Add copyright and license information based on Ben's recollections.
Jerry James <james@xemacs.org>
parents:
2
diff
changeset
|
7 under the terms of the GNU General Public License as published by the |
|
5412
6a8c6c6f6c8e
Convert to GPLv3 or later from plain text GPLv2 or later.
Mats Lidell <matsl@xemacs.org>
parents:
5231
diff
changeset
|
8 Free Software Foundation, either version 3 of the License, or (at your |
|
6a8c6c6f6c8e
Convert to GPLv3 or later from plain text GPLv2 or later.
Mats Lidell <matsl@xemacs.org>
parents:
5231
diff
changeset
|
9 option) any later version. |
|
4894
03ab78e48ef6
Add copyright and license information based on Ben's recollections.
Jerry James <james@xemacs.org>
parents:
2
diff
changeset
|
10 |
|
03ab78e48ef6
Add copyright and license information based on Ben's recollections.
Jerry James <james@xemacs.org>
parents:
2
diff
changeset
|
11 XEmacs is distributed in the hope that it will be useful, but WITHOUT |
|
03ab78e48ef6
Add copyright and license information based on Ben's recollections.
Jerry James <james@xemacs.org>
parents:
2
diff
changeset
|
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
03ab78e48ef6
Add copyright and license information based on Ben's recollections.
Jerry James <james@xemacs.org>
parents:
2
diff
changeset
|
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
03ab78e48ef6
Add copyright and license information based on Ben's recollections.
Jerry James <james@xemacs.org>
parents:
2
diff
changeset
|
14 for more details. |
|
03ab78e48ef6
Add copyright and license information based on Ben's recollections.
Jerry James <james@xemacs.org>
parents:
2
diff
changeset
|
15 |
|
03ab78e48ef6
Add copyright and license information based on Ben's recollections.
Jerry James <james@xemacs.org>
parents:
2
diff
changeset
|
16 You should have received a copy of the GNU General Public License |
|
5412
6a8c6c6f6c8e
Convert to GPLv3 or later from plain text GPLv2 or later.
Mats Lidell <matsl@xemacs.org>
parents:
5231
diff
changeset
|
17 along with XEmacs. If not, see <http://www.gnu.org/licenses/>. */ |
|
4894
03ab78e48ef6
Add copyright and license information based on Ben's recollections.
Jerry James <james@xemacs.org>
parents:
2
diff
changeset
|
18 |
| 2 | 19 #include <Xm/Xm.h> |
| 20 #include <Xm/RowColumn.h> | |
| 21 #include <Xm/Scale.h> | |
| 22 #include <Xm/PushB.h> | |
| 23 #include <Xm/Label.h> | |
| 24 #include <Xm/Text.h> | |
| 25 #include <Xm/PanedW.h> | |
| 26 #include "ExternalClient.h" | |
| 27 | |
| 28 #ifdef TOOLTALK | |
| 29 #include <desktop/tt_c.h> | |
| 30 char *HxProcID; | |
| 31 #endif | |
| 32 | |
| 33 XtAppContext xt_app_con; | |
| 34 | |
| 35 void ScaleValueChangedCB(Widget scale, XtPointer app_data, XtPointer widget_data) | |
| 36 { | |
| 37 XmScaleCallbackStruct *xms = (XmScaleCallbackStruct *) widget_data; | |
| 38 Widget label = (Widget) app_data; | |
| 39 char labelarr[10]; | |
| 40 XmString labelstr; | |
| 41 #if 0 | |
| 42 sprintf(labelarr, "%d", xms->value); | |
| 43 labelstr = XmStringCreateLocalized(labelarr); | |
| 44 XtVaSetValues(label, XmNlabelString, labelstr, NULL); | |
| 45 XmStringFree(labelstr); | |
| 46 #endif | |
| 47 } | |
| 48 | |
| 49 #ifdef TOOLTALK | |
| 50 static void | |
| 51 handle_tt_input(XtPointer client_data, int *source, XtInputId *id) | |
| 52 { | |
| 53 Tt_message m = tt_message_receive(); | |
| 54 | |
| 55 if (m && !(tt_ptr_error(m))) { | |
| 56 tt_message_destroy(m); | |
| 57 } | |
| 58 } | |
| 59 | |
| 60 Tt_status | |
| 61 HxInitializeToolTalk() | |
| 62 { | |
| 63 static Boolean initialized = FALSE; | |
| 64 | |
| 65 if (!initialized) { | |
| 66 int fd; | |
| 67 Tt_status status; | |
| 68 | |
| 69 HxProcID = tt_open(); | |
| 70 fd = tt_fd(); | |
| 71 if (TT_OK != (status = tt_session_join( tt_default_session() ))) | |
| 72 return status; | |
| 73 (void)XtAppAddInput(xt_app_con, fd, (void *)XtInputReadMask, handle_tt_input, NULL); | |
| 74 initialized = TRUE; | |
| 75 } | |
| 76 | |
| 77 return TT_OK; | |
| 78 } | |
| 79 #endif | |
| 80 | |
| 81 main(int argc, char **argv) | |
| 82 { | |
| 83 Widget shell, rowcolumn, scale, pushbutton, label1, label2, text; | |
| 84 Widget paned, text2; | |
| 85 int n, i; | |
| 86 Widget widlist[100]; | |
| 87 Widget emacscli[100]; | |
| 88 Arg args[100]; | |
| 89 int no_ews = 1; | |
| 90 char buf[100]; | |
| 91 | |
| 92 if (argc > 1) | |
| 93 no_ews = atoi (argv[1]); | |
| 94 | |
| 95 shell = XtAppInitialize(&xt_app_con, "Testmotif", NULL, 0, | |
| 96 &argc, argv, NULL, NULL, 0); | |
| 97 | |
| 98 #ifdef TOOLTALK | |
| 99 HxInitializeToolTalk(); | |
| 100 #endif | |
| 101 | |
| 102 rowcolumn = XmCreateRowColumn(shell, "rowcolumn", NULL, 0); | |
| 103 XtManageChild(rowcolumn); | |
| 104 | |
| 105 n = 0; | |
| 106 XtSetArg(args[n], XmNtraversalOn, TRUE); n++; | |
| 107 #if 0 | |
| 108 label1 = XmCreateLabel(rowcolumn, "label1", args, n); | |
| 109 #endif | |
| 110 label1 = XtVaCreateWidget("label1", xmLabelWidgetClass, rowcolumn, | |
| 111 XmNwidth, 50, XmNheight, 30, | |
| 112 XmNtraversalOn, TRUE, NULL); | |
| 113 label2 = XmCreateLabel(rowcolumn, "label2", NULL, 0); | |
| 114 scale = XmCreateScale(rowcolumn, "scale", NULL, 0); | |
| 115 XtAddCallback(scale, XmNvalueChangedCallback, ScaleValueChangedCB, label1); | |
| 116 paned = XmCreatePanedWindow(rowcolumn, "paned", NULL, 0); | |
| 117 n = 0; | |
| 118 widlist[n++] = label1; | |
| 119 widlist[n++] = label2; | |
| 120 widlist[n++] = scale; | |
| 121 widlist[n++] = paned; | |
| 122 XtManageChildren(widlist, n); | |
| 123 | |
| 124 pushbutton = XmCreatePushButton(paned, "pushbutton", NULL, 0); | |
| 125 text = XmCreateText(paned, "text", NULL, 0); | |
| 126 for (i=0; i<no_ews; i++) { | |
| 127 sprintf (buf, "extcli%d", i); | |
| 128 emacscli[i] = XtVaCreateWidget(buf, externalClientWidgetClass, paned, | |
| 129 XmNwidth, 500, XmNheight, 200, | |
| 130 XmNtraversalOn, TRUE, | |
| 131 #ifdef TOOLTALK | |
| 132 XtNuseToolTalk, TRUE, | |
| 133 #endif | |
| 134 NULL); | |
| 135 } | |
| 136 text2 = XmCreateText(paned, "text2", NULL, 0); | |
| 137 n = 0; | |
| 138 widlist[n++] = pushbutton; | |
| 139 widlist[n++] = text; | |
| 140 for (i=0; i<no_ews; i++) | |
| 141 widlist[n++] = emacscli[i]; | |
| 142 widlist[n++] = text2; | |
| 143 XtManageChildren(widlist, n); | |
| 144 | |
| 145 XtRealizeWidget(shell); | |
| 146 | |
| 147 { | |
| 148 XmString lab; | |
| 149 char labarr[1000]; | |
| 150 char tmpbuf[50]; | |
| 151 | |
| 152 strcpy (labarr, "window:"); | |
| 153 for (i=0; i<no_ews; i++) { | |
| 154 sprintf (tmpbuf, " %d", XtWindow(emacscli[i])); | |
| 155 strcat (labarr, tmpbuf); | |
| 156 } | |
| 157 lab = XmStringCreateLocalized(labarr); | |
| 158 XtVaSetValues(label2, XmNlabelString, lab, NULL); | |
| 159 XmStringFree(lab); | |
| 160 } | |
| 161 | |
| 162 XtAppMainLoop(xt_app_con); | |
| 163 } |
