ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/W11/wrap/wrap.c
Revision: 1.1
Committed: Mon Nov 24 17:28:08 2003 UTC (20 years, 7 months ago) by pcg
Content type: text/plain
Branch: MAIN
CVS Tags: rel-7_0, post_menubar_removal, rel-6_2, rel-6_3, rel-6_0, rel-6_1, rel-2_1_0, rel-5_5, rel-5_4, rel-5_7, rel-5_1, rel-5_0, rel-5_3, rel-5_2, rel-4_4, rel-4_6, rel-4_7, rel-5_9, rel-5_8, rel-4_2, rel-4_3, rel-3_7, rel-3_8, rel-3_5, rel-3_4, rel-3_3, rel-3_2, rel-2_8, rel-3_0, rel-4_0, rel-2_4, rel-2_5, rel-2_2, rel-2_3, rel-2_0, rel-4_1, rel-1-9, rel-1-3, rel-1-2, rxvt-2-0, rel-1_9, rel-3_6, rel-2_7, rel-4_8, rel-4_9
Log Message:
*** empty log message ***

File Contents

# User Rev Content
1 pcg 1.1
2     #include <X11/Xlib.h>
3     #include <windows.h>
4     #include <stdio.h>
5     #include <stdlib.h>
6     #include <malloc.h>
7     #include "wrap.h"
8    
9     void __cdecl WinMainCRTStartup(void) { mainCRTStartup(); }
10    
11     static void *_lib=NULL;
12     static char *_libname = NULL;
13    
14     static void *_loadfunc(char *name)
15     {
16     void *f = NULL;
17     if (_lib==NULL) {
18     if (_libname==NULL) {
19     fprintf(stderr,"%s called before XOpenDisplay!\n",name);
20     exit(3);
21     }
22     _lib = LoadLibrary(_libname);
23     if (_lib == NULL) {
24     fprintf(stderr,"failed to load %s.dll\n",_libname);
25     exit(1);
26     }
27     }
28     f = GetProcAddress(_lib,name);
29     if (f==NULL) {
30     fprintf(stderr,"failed to find %s\n",name);
31     exit(2);
32     }
33     return f;
34     }
35    
36     static void _freelib()
37     {
38     FreeLibrary(_lib);
39     _lib=NULL;
40     }
41     typedef LONG (proto_WndProc)(HWND hWnd,UINT message,UINT wParam,LONG lParam);
42     static proto_WndProc *func_WndProc = NULL;
43     LONG __stdcall WndProc(HWND hWnd,UINT message,UINT wParam,LONG lParam)
44     {
45     if (!func_WndProc) func_WndProc=(proto_WndProc *)_loadfunc("NT_handleMsg");
46     return (func_WndProc)(hWnd,message,wParam,lParam);
47     }
48    
49     static void
50     hideConsole()
51     {
52     HWND conwin;
53     HANDLE hConsole;
54     CONSOLE_SCREEN_BUFFER_INFO buffInfo;
55     SECURITY_ATTRIBUTES sa;
56    
57     char app_name[40];
58     sprintf(app_name, "rxvt%08x", (unsigned int)GetCurrentThreadId());
59     /* from eConsole source */
60     sa.nLength = sizeof(sa);
61     sa.bInheritHandle = TRUE;
62     sa.lpSecurityDescriptor = NULL;
63     hConsole = CreateFile( "CONOUT$", GENERIC_WRITE | GENERIC_READ,
64     FILE_SHARE_READ | FILE_SHARE_WRITE, &sa,
65     OPEN_EXISTING, 0, 0 );
66     if (GetConsoleScreenBufferInfo(hConsole,&buffInfo) &&
67     buffInfo.dwCursorPosition.X==0 &&
68     buffInfo.dwCursorPosition.Y==0)
69     {
70     /* find the console window, from eConsole source */
71     SetConsoleTitle( app_name );
72     while ((conwin = FindWindow( NULL, app_name))==NULL)
73     Sleep( 40 );
74     ShowWindowAsync(conwin, SW_HIDE);
75     }
76     }
77    
78    
79     ATOM
80     _register_window_class()
81     {
82     WNDCLASS wc;
83     HANDLE curInstance = GetModuleHandleA(NULL);
84     char app_name[40];
85     sprintf(app_name, "rxvt%08x", (unsigned int)GetCurrentThreadId());
86     hideConsole();
87     wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC; /* CS_OWNDC */
88     wc.lpfnWndProc = WndProc;
89     wc.cbClsExtra = 0;
90     wc.cbWndExtra = 0;
91     wc.hInstance = curInstance;
92     wc.hIcon = LoadIcon(curInstance, MAKEINTRESOURCE( IDI_RXVT ));
93     wc.hCursor = LoadCursor(NULL, IDC_ARROW);
94     wc.hbrBackground = NULL;
95     wc.lpszMenuName = NULL;
96     wc.lpszClassName = app_name;
97     return RegisterClass(&wc);
98     }
99    
100     typedef void (proto_NT_SetAtom)(ATOM class);
101     static proto_NT_SetAtom *func_NT_SetAtom = NULL;
102     void _set_atom(ATOM class)
103     {
104     if (!func_NT_SetAtom) func_NT_SetAtom=(proto_NT_SetAtom *)_loadfunc("NT_SetAtom");
105     (func_NT_SetAtom)(class);
106     }
107    
108     typedef void (proto_W11AddEventHandler)(Display *d, proto_W11EventHandler *ev);
109     static proto_W11AddEventHandler *func_W11AddEventHandler = NULL;
110     void W11AddEventHandler(Display *d, proto_W11EventHandler *ev)
111     {
112     if (func_W11AddEventHandler)
113     (func_W11AddEventHandler)(d,ev);
114     }
115    
116     typedef Display * (proto_XOpenDisplay)(const char *name);
117     static proto_XOpenDisplay *func_XOpenDisplay = NULL;
118     Display * XOpenDisplay(const char *name) {
119     ATOM class;
120     char *env_var=NULL;
121     if (_libname==NULL)
122     {
123     env_var = getenv("W11_LIBRARY");
124     if (env_var!=NULL) _libname = strdup(env_var);
125     else if (name==NULL || !strcmp(name,":0")) {
126     _libname="libW11";
127     class = _register_window_class();
128     _set_atom(class);
129     func_W11AddEventHandler=(proto_W11AddEventHandler *)_loadfunc("W11AddEventHandler");
130     }
131     else _libname="libX11";
132     }
133     if (!func_XOpenDisplay) func_XOpenDisplay=(proto_XOpenDisplay *)_loadfunc("XOpenDisplay");
134     return (func_XOpenDisplay)(name);
135     }
136    
137     typedef struct {
138     char *name;
139     XPointer value;
140     } XIMArg;
141    
142     static void
143     _XIMVaToList(va_list var, XIMArg *args)
144     {
145     char *attr;
146     int i = 0;
147     if (!args) return;
148     for (attr = va_arg(var, char*); attr && i<11; attr = va_arg(var, char*)) {
149     args->name = attr;
150     args->value = va_arg(var, XPointer);
151     args++;
152     i++;
153     }
154     for(;i<11;i++) {
155     args->name=NULL;
156     args->value=NULL;
157     args++;
158     }
159     }
160    
161     typedef XIC (proto_XCreateIC)(XIM im, ...);
162     static proto_XCreateIC *func_XCreateIC = NULL;
163     XIC
164     XCreateIC(XIM im, ...)
165     {
166     va_list var;
167     XIMArg a[11];
168    
169     va_start(var, im);
170     _XIMVaToList(var, a);
171     va_end(var);
172    
173     if (a[10].name!=NULL) {
174     fprintf(stderr,"call to XCreateIC with more than 20 args\n");
175     exit(5);
176     }
177    
178     if (!func_XCreateIC) func_XCreateIC=(proto_XCreateIC *)_loadfunc("XCreateIC");
179     return (func_XCreateIC)(im,
180     a[0].name, a[0].value,
181     a[1].name, a[1].value,
182     a[2].name, a[2].value,
183     a[3].name, a[3].value,
184     a[4].name, a[4].value,
185     a[5].name, a[5].value,
186     a[6].name, a[6].value,
187     a[7].name, a[7].value,
188     a[8].name, a[8].value,
189     a[9].name, a[9].value,
190     NULL);
191     }
192    
193     typedef char * (proto_XGetIMValues)(XIM im, ...);
194     static proto_XGetIMValues *func_XGetIMValues = NULL;
195     char *
196     XGetIMValues(XIM im, ...)
197     {
198     va_list var;
199     XIMArg a[11];
200    
201     va_start(var, im);
202     _XIMVaToList(var, a);
203     va_end(var);
204    
205     if (a[10].name!=NULL) {
206     fprintf(stderr,"call to XGetIMValues with more than 20 args\n");
207     exit(5);
208     }
209    
210     if (!func_XGetIMValues) func_XGetIMValues=(proto_XGetIMValues *)_loadfunc("XGetIMValues");
211     return (func_XGetIMValues)(im,
212     a[0].name, a[0].value,
213     a[1].name, a[1].value,
214     a[2].name, a[2].value,
215     a[3].name, a[3].value,
216     a[4].name, a[4].value,
217     a[5].name, a[5].value,
218     a[6].name, a[6].value,
219     a[7].name, a[7].value,
220     a[8].name, a[8].value,
221     a[9].name, a[9].value,
222     NULL);
223     }
224    
225    
226     #include "xwrappers.gen"