OSDN Git Service

FIRST REPOSITORY
[eos/hostdependOTHERS.git] / I386LINUX / util / I386LINUX / doc / mico / examples / dispatcher / x11 / client.cc
1 /*
2  *  MICO --- a free CORBA implementation
3  *  Copyright (C) 1997-98 Kay Roemer & Arno Puder
4  *
5  *  This program is free software; you can redistribute it and/or modify
6  *  it under the terms of the GNU General Public License as published by
7  *  the Free Software Foundation; either version 2 of the License, or
8  *  (at your option) any later version.
9  *
10  *  This program is distributed in the hope that it will be useful,
11  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  *  GNU General Public License for more details.
14  *
15  *  You should have received a copy of the GNU General Public License
16  *  along with this program; if not, write to the Free Software
17  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  *
19  *  Send comments and/or bug reports to:
20  *                 mico@informatik.uni-frankfurt.de
21  */
22
23 #include <CORBA-SMALL.h>
24 #ifdef HAVE_ANSI_CPLUSPLUS_HEADERS
25 #include <iostream>
26 #else
27 #include <iostream.h>
28 #endif
29 #include "hello.h"
30 #include <mico/x11.h>
31
32 #include <X11/Intrinsic.h>
33 #include <X11/StringDefs.h>
34 #include <X11/Xaw/Command.h>
35 #include <X11/Xaw/AsciiText.h>
36 #include <X11/Xaw/Form.h>
37
38
39 using namespace std;
40
41 Widget top, form, entry, quit;
42
43 HelloWorld_var hello_client;
44
45 void
46 return_cb (Widget, XEvent *, String *, Cardinal *)
47 {
48     String arg;
49     XtVaGetValues (entry,
50                    XtNstring, &arg,
51                    NULL);
52
53     hello_client->hello (arg);
54 }
55
56 void
57 quit_cb (Widget, XtPointer, XtPointer)
58 {
59     exit (1);
60 }
61
62 int
63 main (int argc, char *argv[])
64 {
65     /*
66      * MICO initialization
67      */
68     CORBA::ORB_var orb = CORBA::ORB_init (argc, argv, "mico-local-orb");
69
70     /*
71      * X11 initialization
72      */
73     static String fallback_res[] = {
74         "*quit.label: Quit",
75         NULL
76     };
77
78     XtAppContext appctx;
79     top = XtAppInitialize (&appctx, "Xhello",
80                            0, 0,
81                            &argc, argv,
82                            fallback_res,
83                            0, 0);
84
85     /*
86      * Use X11 dispatcher
87      */
88     orb->dispatcher (new X11Dispatcher (appctx));
89
90
91     /*
92      * MICO stuff
93      */
94     assert (argc == 2);
95     CORBA::Object_var obj = orb->bind ("IDL:HelloWorld:1.0", argv[1]);
96     if (CORBA::is_nil (obj)) {
97         cout << "cannot bind to " << argv[1] << endl;
98         return 1;
99     }
100     hello_client = HelloWorld::_narrow (obj);
101
102
103     /*
104      * X11 stuff
105      */
106     form = XtVaCreateManagedWidget ("form",
107                                    formWidgetClass,
108                                    top,
109                                    NULL);
110
111     // entry field
112     entry = XtVaCreateManagedWidget ("argument",
113                                      asciiTextWidgetClass,
114                                      form,
115                                      XtNwidth, 150,
116                                      XtNeditType, XawtextEdit,
117                                      XtNresizable, True,
118                                      XtNresize, XawtextResizeWidth,
119                                      NULL);
120     XtTranslations trans
121         = XtParseTranslationTable ("<Key>Return: ReturnAction()\n");
122     XtOverrideTranslations (entry, trans);
123
124     static XtActionsRec actions[] = {
125         { "ReturnAction", return_cb }
126     };
127     XtAppAddActions (appctx, actions, XtNumber (actions));
128
129     // quit button
130     quit = XtVaCreateManagedWidget ("quit",
131                                     commandWidgetClass,
132                                     form,
133                                     XtNfromVert, entry,
134                                     NULL);
135     XtAddCallback (quit, XtNcallback, quit_cb, 0);
136
137
138     XtRealizeWidget (top);
139     XtAppMainLoop (appctx);
140
141     return 0;
142 }
143
144