Joseph Rosevear
2010-03-07 04:50:55 UTC
Hello to you in comp.soft-sys.wxwindows,
I'm new to this news group and also new to X programming. Let me
introduce myself. I know a little C programming, and I'm somewhat
skilled in Bash. I've been a Slackware Linux user for about ten years.
I came here hoping to learn a little by getting help with a problem. I
found an example Athena widgets program. The source is called
"text.c". I'll provide it at the end of this post. I found text.c in
a book called _Linux_Programming_Unleashed_ by Kurt Wall, et al. and
published by Sams Publishing.
At first I was sure that there was something terrible happening which I
could not explain. I struggled with it for several hours. Finally,
exhausted, I looked for a news group where I could post a question. I
found this news group, and here I am.
I wrote a message about the problem. I explained that the compiled
program, "text", worked correctly for me only in the TWM window manager
on my Slackware 12.0 system. I tried Kde, Fluxbox, Fvwm2, and Xfce
also, but they all showed a peculiar problem. Which was this: They
would allow a repositioning of the box shaped cursor (by clicking in
the Widget window), but they would never allow the widget window to
accept the text that I would try to type into it. In fact, except for
the cursor repositioning, I got no sign that the window had accepted
the focus.
Well, I got all the way to the end of my message and I mentioned what
page of the book the source code came from and how I compiled it. As
often happens, my carefully phrased question prompted me to discover
the answer myself. Ha! I had compiled text.c incorrectly! The book
provided a Makefile and compilation instructions.
After compiling per the book's instructions the text program worked
perfectly in Fvwm2. I have not yet tried it in the other window
managers that I mentioned, so I'll do that after I post this and let
you know if I found any trouble.
So, my mistake was one of compilation it seems.
Here is the wrong compilation:
cc text.c -o text -l X11 -l Xt -l Xaw
And here is the one that was provided by the book (and seems to be OK):
cc -o text text.c -L/usr/X11R6/lib -lX11 -lXaw
I believe these two differences may be significant:
1. I initially used "-l Xt" instead of "-L/usr/X11R6/lib"
2. I listed the libraries in a different order
So what is going on here? Does anyone out there know the how and why
of listing libraries when compiling? I don't know if the order of
listing libraries matters. I also don't know what the difference is
between "-l Xt" and "-L/usr/X11R6/lib".
Help me to understand if you can.
Thanks.
-Joe
Here is the source for text.c:
***
#include <X11/Intrinsic.h>
#include <X11/StringDefs.h>
#include <X11/Xaw/Paned.h>
#include <X11/Xaw/AsciiText.h>
#include <X11/Xaw/Command.h>
void do_display_widget_text(Widget w, XtPointer text_ptr, XtPointer unused) {
Widget text = (Widget) text_ptr;
String str;
XtVaGetValues(text,
XtNstring, &str,
NULL);
printf("Widget Text is:\n%s\n", str);
}
void do_erase_text_widget(Widget w, XtPointer text_ptr, XtPointer unused) {
Widget text = (Widget) text_ptr;
XtVaSetValues(text,
XtNstring, "",
NULL);
}
XtAppContext application_context;
void do_quit(Widget w, XtPointer unused1, XtPointer unused2) {
XtDestroyApplicationContext(application_context);
exit(0);
}
String app_resources[] = {
"*Text*editType: edit",
"*Text*autoFill: on",
"*Text*scrollVertical: whenNeeded",
"*Text*scrollHorizontal: whenNeeded",
"*erase*label: Erase the text widget",
"*display*label: Display the text from the text widget",
"*Text*preferredPaneSize: 300",
NULL,
};
int main(int argc, char **argv) {
Widget top_level, paned, text, erase, display, quit;
char *initial_text= "Try typing\n\nsome text here!\n\n";
top_level = XtAppInitialize(&application_context, "textexample", NULL, 0,
&argc, argv, app_resources,
NULL, 0);
paned = XtVaCreateManagedWidget("paned", panedWidgetClass, top_level,
NULL);
text = XtVaCreateManagedWidget("text", asciiTextWidgetClass, paned,
XtNtype, XawAsciiString,
XtNstring, initial_text,
NULL);
erase = XtVaCreateManagedWidget("erase", commandWidgetClass, paned,
NULL);
display = XtVaCreateManagedWidget("display", commandWidgetClass, paned,
NULL);
quit = XtVaCreateManagedWidget("quit", commandWidgetClass, paned,
NULL);
XtAddCallback(erase, XtNcallback, do_erase_text_widget, (XtPointer) text);
XtAddCallback(display, XtNcallback, do_display_widget_text, (XtPointer) text);
XtAddCallback(quit, XtNcallback, do_quit, (XtPointer) text);
XtRealizeWidget(top_level);
XtAppMainLoop(application_context);
return 0;
}
***
This example comes from page 602 in chapter 26.
I'm new to this news group and also new to X programming. Let me
introduce myself. I know a little C programming, and I'm somewhat
skilled in Bash. I've been a Slackware Linux user for about ten years.
I came here hoping to learn a little by getting help with a problem. I
found an example Athena widgets program. The source is called
"text.c". I'll provide it at the end of this post. I found text.c in
a book called _Linux_Programming_Unleashed_ by Kurt Wall, et al. and
published by Sams Publishing.
At first I was sure that there was something terrible happening which I
could not explain. I struggled with it for several hours. Finally,
exhausted, I looked for a news group where I could post a question. I
found this news group, and here I am.
I wrote a message about the problem. I explained that the compiled
program, "text", worked correctly for me only in the TWM window manager
on my Slackware 12.0 system. I tried Kde, Fluxbox, Fvwm2, and Xfce
also, but they all showed a peculiar problem. Which was this: They
would allow a repositioning of the box shaped cursor (by clicking in
the Widget window), but they would never allow the widget window to
accept the text that I would try to type into it. In fact, except for
the cursor repositioning, I got no sign that the window had accepted
the focus.
Well, I got all the way to the end of my message and I mentioned what
page of the book the source code came from and how I compiled it. As
often happens, my carefully phrased question prompted me to discover
the answer myself. Ha! I had compiled text.c incorrectly! The book
provided a Makefile and compilation instructions.
After compiling per the book's instructions the text program worked
perfectly in Fvwm2. I have not yet tried it in the other window
managers that I mentioned, so I'll do that after I post this and let
you know if I found any trouble.
So, my mistake was one of compilation it seems.
Here is the wrong compilation:
cc text.c -o text -l X11 -l Xt -l Xaw
And here is the one that was provided by the book (and seems to be OK):
cc -o text text.c -L/usr/X11R6/lib -lX11 -lXaw
I believe these two differences may be significant:
1. I initially used "-l Xt" instead of "-L/usr/X11R6/lib"
2. I listed the libraries in a different order
So what is going on here? Does anyone out there know the how and why
of listing libraries when compiling? I don't know if the order of
listing libraries matters. I also don't know what the difference is
between "-l Xt" and "-L/usr/X11R6/lib".
Help me to understand if you can.
Thanks.
-Joe
Here is the source for text.c:
***
#include <X11/Intrinsic.h>
#include <X11/StringDefs.h>
#include <X11/Xaw/Paned.h>
#include <X11/Xaw/AsciiText.h>
#include <X11/Xaw/Command.h>
void do_display_widget_text(Widget w, XtPointer text_ptr, XtPointer unused) {
Widget text = (Widget) text_ptr;
String str;
XtVaGetValues(text,
XtNstring, &str,
NULL);
printf("Widget Text is:\n%s\n", str);
}
void do_erase_text_widget(Widget w, XtPointer text_ptr, XtPointer unused) {
Widget text = (Widget) text_ptr;
XtVaSetValues(text,
XtNstring, "",
NULL);
}
XtAppContext application_context;
void do_quit(Widget w, XtPointer unused1, XtPointer unused2) {
XtDestroyApplicationContext(application_context);
exit(0);
}
String app_resources[] = {
"*Text*editType: edit",
"*Text*autoFill: on",
"*Text*scrollVertical: whenNeeded",
"*Text*scrollHorizontal: whenNeeded",
"*erase*label: Erase the text widget",
"*display*label: Display the text from the text widget",
"*Text*preferredPaneSize: 300",
NULL,
};
int main(int argc, char **argv) {
Widget top_level, paned, text, erase, display, quit;
char *initial_text= "Try typing\n\nsome text here!\n\n";
top_level = XtAppInitialize(&application_context, "textexample", NULL, 0,
&argc, argv, app_resources,
NULL, 0);
paned = XtVaCreateManagedWidget("paned", panedWidgetClass, top_level,
NULL);
text = XtVaCreateManagedWidget("text", asciiTextWidgetClass, paned,
XtNtype, XawAsciiString,
XtNstring, initial_text,
NULL);
erase = XtVaCreateManagedWidget("erase", commandWidgetClass, paned,
NULL);
display = XtVaCreateManagedWidget("display", commandWidgetClass, paned,
NULL);
quit = XtVaCreateManagedWidget("quit", commandWidgetClass, paned,
NULL);
XtAddCallback(erase, XtNcallback, do_erase_text_widget, (XtPointer) text);
XtAddCallback(display, XtNcallback, do_display_widget_text, (XtPointer) text);
XtAddCallback(quit, XtNcallback, do_quit, (XtPointer) text);
XtRealizeWidget(top_level);
XtAppMainLoop(application_context);
return 0;
}
***
This example comes from page 602 in chapter 26.