~paulliu/ubuntu/precise/freerdp/fixext

« back to all changes in this revision

Viewing changes to win/wfreerdp/wf_win.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Otavio Salvador
  • Date: 2010-10-25 14:29:02 UTC
  • mto: (9.1.1 sid) (1.1.7)
  • mto: This revision was merged to the branch mainline in revision 6.
  • Revision ID: james.westby@ubuntu.com-20101025142902-j8hmshnnxhu61l4m
Tags: upstream-0.8.1
ImportĀ upstreamĀ versionĀ 0.8.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
   Copyright (c) 2009 Jay Sorg
 
3
   Copyright (c) 2010 Vic Lee
 
4
 
 
5
   Permission is hereby granted, free of charge, to any person obtaining a
 
6
   copy of this software and associated documentation files (the "Software"),
 
7
   to deal in the Software without restriction, including without limitation
 
8
   the rights to use, copy, modify, merge, publish, distribute, sublicense,
 
9
   and/or sell copies of the Software, and to permit persons to whom the
 
10
   Software is furnished to do so, subject to the following conditions:
 
11
 
 
12
   The above copyright notice and this permission notice shall be included
 
13
   in all copies or substantial portions of the Software.
 
14
 
 
15
   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 
16
   OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 
17
   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 
18
   AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 
19
   LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 
20
   FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 
21
   DEALINGS IN THE SOFTWARE.
 
22
*/
 
23
 
 
24
#include <windows.h>
 
25
#include <stdio.h>
 
26
#include <stdlib.h>
 
27
#include <string.h>
 
28
#include "wf_event.h"
 
29
#include "wf_color.h"
 
30
#include "wf_win.h"
 
31
 
 
32
extern LPCTSTR g_wnd_class_name;
 
33
extern HINSTANCE g_hInstance;
 
34
extern HCURSOR g_default_cursor;
 
35
 
 
36
// See http://msdn.microsoft.com/en-us/library/dd145130(VS.85).aspx
 
37
static const DWORD rop3_code_table[] =
 
38
{
 
39
        0x00000042, // 0
 
40
        0x00010289, // DPSoon
 
41
        0x00020C89, // DPSona
 
42
        0x000300AA, // PSon
 
43
        0x00040C88, // SDPona
 
44
        0x000500A9, // DPon
 
45
        0x00060865, // PDSxnon
 
46
        0x000702C5, // PDSaon
 
47
        0x00080F08, // SDPnaa
 
48
        0x00090245, // PDSxon
 
49
        0x000A0329, // DPna
 
50
        0x000B0B2A, // PSDnaon
 
51
        0x000C0324, // SPna
 
52
        0x000D0B25, // PDSnaon
 
53
        0x000E08A5, // PDSonon
 
54
        0x000F0001, // Pn
 
55
        0x00100C85, // PDSona
 
56
        0x001100A6, // DSon
 
57
        0x00120868, // SDPxnon
 
58
        0x001302C8, // SDPaon
 
59
        0x00140869, // DPSxnon
 
60
        0x001502C9, // DPSaon
 
61
        0x00165CCA, // PSDPSanaxx
 
62
        0x00171D54, // SSPxDSxaxn
 
63
        0x00180D59, // SPxPDxa
 
64
        0x00191CC8, // SDPSanaxn
 
65
        0x001A06C5, // PDSPaox
 
66
        0x001B0768, // SDPSxaxn
 
67
        0x001C06CA, // PSDPaox
 
68
        0x001D0766, // DSPDxaxn
 
69
        0x001E01A5, // PDSox
 
70
        0x001F0385, // PDSoan
 
71
        0x00200F09, // DPSnaa
 
72
        0x00210248, // SDPxon
 
73
        0x00220326, // DSna
 
74
        0x00230B24, // SPDnaon
 
75
        0x00240D55, // SPxDSxa
 
76
        0x00251CC5, // PDSPanaxn
 
77
        0x002606C8, // SDPSaox
 
78
        0x00271868, // SDPSxnox
 
79
        0x00280369, // DPSxa
 
80
        0x002916CA, // PSDPSaoxxn
 
81
        0x002A0CC9, // DPSana
 
82
        0x002B1D58, // SSPxPDxaxn
 
83
        0x002C0784, // SPDSoax
 
84
        0x002D060A, // PSDnox
 
85
        0x002E064A, // PSDPxox
 
86
        0x002F0E2A, // PSDnoan
 
87
        0x0030032A, // PSna
 
88
        0x00310B28, // SDPnaon
 
89
        0x00320688, // SDPSoox
 
90
        0x00330008, // Sn
 
91
        0x003406C4, // SPDSaox
 
92
        0x00351864, // SPDSxnox
 
93
        0x003601A8, // SDPox
 
94
        0x00370388, // SDPoan
 
95
        0x0038078A, // PSDPoax
 
96
        0x00390604, // SPDnox
 
97
        0x003A0644, // SPDSxox
 
98
        0x003B0E24, // SPDnoan
 
99
        0x003C004A, // PSx
 
100
        0x003D18A4, // SPDSonox
 
101
        0x003E1B24, // SPDSnaox
 
102
        0x003F00EA, // PSan
 
103
        0x00400F0A, // PSDnaa
 
104
        0x00410249, // DPSxon
 
105
        0x00420D5D, // SDxPDxa
 
106
        0x00431CC4, // SPDSanaxn
 
107
        0x00440328, // SDna
 
108
        0x00450B29, // DPSnaon
 
109
        0x004606C6, // DSPDaox
 
110
        0x0047076A, // PSDPxaxn
 
111
        0x00480368, // SDPxa
 
112
        0x004916C5, // PDSPDaoxxn
 
113
        0x004A0789, // DPSDoax
 
114
        0x004B0605, // PDSnox
 
115
        0x004C0CC8, // SDPana
 
116
        0x004D1954, // SSPxDSxoxn
 
117
        0x004E0645, // PDSPxox
 
118
        0x004F0E25, // PDSnoan
 
119
        0x00500325, // PDna
 
120
        0x00510B26, // DSPnaon
 
121
        0x005206C9, // DPSDaox
 
122
        0x00530764, // SPDSxaxn
 
123
        0x005408A9, // DPSonon
 
124
        0x00550009, // Dn
 
125
        0x005601A9, // DPSox
 
126
        0x00570389, // DPSoan
 
127
        0x00580785, // PDSPoax
 
128
        0x00590609, // DPSnox
 
129
        0x005A0049, // DPx
 
130
        0x005B18A9, // DPSDonox
 
131
        0x005C0649, // DPSDxox
 
132
        0x005D0E29, // DPSnoan
 
133
        0x005E1B29, // DPSDnaox
 
134
        0x005F00E9, // DPan
 
135
        0x00600365, // PDSxa
 
136
        0x006116C6, // DSPDSaoxxn
 
137
        0x00620786, // DSPDoax
 
138
        0x00630608, // SDPnox
 
139
        0x00640788, // SDPSoax
 
140
        0x00650606, // DSPnox
 
141
        0x00660046, // DSx
 
142
        0x006718A8, // SDPSonox
 
143
        0x006858A6, // DSPDSonoxxn
 
144
        0x00690145, // PDSxxn
 
145
        0x006A01E9, // DPSax
 
146
        0x006B178A, // PSDPSoaxxn
 
147
        0x006C01E8, // SDPax
 
148
        0x006D1785, // PDSPDoaxxn
 
149
        0x006E1E28, // SDPSnoax
 
150
        0x006F0C65, // PDSxnan
 
151
        0x00700CC5, // PDSana
 
152
        0x00711D5C, // SSDxPDxaxn
 
153
        0x00720648, // SDPSxox
 
154
        0x00730E28, // SDPnoan
 
155
        0x00740646, // DSPDxox
 
156
        0x00750E26, // DSPnoan
 
157
        0x00761B28, // SDPSnaox
 
158
        0x007700E6, // DSan
 
159
        0x007801E5, // PDSax
 
160
        0x00791786, // DSPDSoaxxn
 
161
        0x007A1E29, // DPSDnoax
 
162
        0x007B0C68, // SDPxnan
 
163
        0x007C1E24, // SPDSnoax
 
164
        0x007D0C69, // DPSxnan
 
165
        0x007E0955, // SPxDSxo
 
166
        0x007F03C9, // DPSaan
 
167
        0x008003E9, // DPSaa
 
168
        0x00810975, // SPxDSxon
 
169
        0x00820C49, // DPSxna
 
170
        0x00831E04, // SPDSnoaxn
 
171
        0x00840C48, // SDPxna
 
172
        0x00851E05, // PDSPnoaxn
 
173
        0x008617A6, // DSPDSoaxx
 
174
        0x008701C5, // PDSaxn
 
175
        0x008800C6, // DSa
 
176
        0x00891B08, // SDPSnaoxn
 
177
        0x008A0E06, // DSPnoa
 
178
        0x008B0666, // DSPDxoxn
 
179
        0x008C0E08, // SDPnoa
 
180
        0x008D0668, // SDPSxoxn
 
181
        0x008E1D7C, // SSDxPDxax
 
182
        0x008F0CE5, // PDSanan
 
183
        0x00900C45, // PDSxna
 
184
        0x00911E08, // SDPSnoaxn
 
185
        0x009217A9, // DPSDPoaxx
 
186
        0x009301C4, // SPDaxn
 
187
        0x009417AA, // PSDPSoaxx
 
188
        0x009501C9, // DPSaxn
 
189
        0x00960169, // DPSxx
 
190
        0x0097588A, // PSDPSonoxx
 
191
        0x00981888, // SDPSonoxn
 
192
        0x00990066, // DSxn
 
193
        0x009A0709, // DPSnax
 
194
        0x009B07A8, // SDPSoaxn
 
195
        0x009C0704, // SPDnax
 
196
        0x009D07A6, // DSPDoaxn
 
197
        0x009E16E6, // DSPDSaoxx
 
198
        0x009F0345, // PDSxan
 
199
        0x00A000C9, // DPa
 
200
        0x00A11B05, // PDSPnaoxn
 
201
        0x00A20E09, // DPSnoa
 
202
        0x00A30669, // DPSDxoxn
 
203
        0x00A41885, // PDSPonoxn
 
204
        0x00A50065, // PDxn
 
205
        0x00A60706, // DSPnax
 
206
        0x00A707A5, // PDSPoaxn
 
207
        0x00A803A9, // DPSoa
 
208
        0x00A90189, // DPSoxn
 
209
        0x00AA0029, // D
 
210
        0x00AB0889, // DPSono
 
211
        0x00AC0744, // SPDSxax
 
212
        0x00AD06E9, // DPSDaoxn
 
213
        0x00AE0B06, // DSPnao
 
214
        0x00AF0229, // DPno
 
215
        0x00B00E05, // PDSnoa
 
216
        0x00B10665, // PDSPxoxn
 
217
        0x00B21974, // SSPxDSxox
 
218
        0x00B30CE8, // SDPanan
 
219
        0x00B4070A, // PSDnax
 
220
        0x00B507A9, // DPSDoaxn
 
221
        0x00B616E9, // DPSDPaoxx
 
222
        0x00B70348, // SDPxan
 
223
        0x00B8074A, // PSDPxax
 
224
        0x00B906E6, // DSPDaoxn
 
225
        0x00BA0B09, // DPSnao
 
226
        0x00BB0226, // DSno
 
227
        0x00BC1CE4, // SPDSanax
 
228
        0x00BD0D7D, // SDxPDxan
 
229
        0x00BE0269, // DPSxo
 
230
        0x00BF08C9, // DPSano
 
231
        0x00C000CA, // PSa
 
232
        0x00C11B04, // SPDSnaoxn
 
233
        0x00C21884, // SPDSonoxn
 
234
        0x00C3006A, // PSxn
 
235
        0x00C40E04, // SPDnoa
 
236
        0x00C50664, // SPDSxoxn
 
237
        0x00C60708, // SDPnax
 
238
        0x00C707AA, // PSDPoaxn
 
239
        0x00C803A8, // SDPoa
 
240
        0x00C90184, // SPDoxn
 
241
        0x00CA0749, // DPSDxax
 
242
        0x00CB06E4, // SPDSaoxn
 
243
        0x00CC0020, // S
 
244
        0x00CD0888, // SDPono
 
245
        0x00CE0B08, // SDPnao
 
246
        0x00CF0224, // SPno
 
247
        0x00D00E0A, // PSDnoa
 
248
        0x00D1066A, // PSDPxoxn
 
249
        0x00D20705, // PDSnax
 
250
        0x00D307A4, // SPDSoaxn
 
251
        0x00D41D78, // SSPxPDxax
 
252
        0x00D50CE9, // DPSanan
 
253
        0x00D616EA, // PSDPSaoxx
 
254
        0x00D70349, // DPSxan
 
255
        0x00D80745, // PDSPxax
 
256
        0x00D906E8, // SDPSaoxn
 
257
        0x00DA1CE9, // DPSDanax
 
258
        0x00DB0D75, // SPxDSxan
 
259
        0x00DC0B04, // SPDnao
 
260
        0x00DD0228, // SDno
 
261
        0x00DE0268, // SDPxo
 
262
        0x00DF08C8, // SDPano
 
263
        0x00E003A5, // PDSoa
 
264
        0x00E10185, // PDSoxn
 
265
        0x00E20746, // DSPDxax
 
266
        0x00E306EA, // PSDPaoxn
 
267
        0x00E40748, // SDPSxax
 
268
        0x00E506E5, // PDSPaoxn
 
269
        0x00E61CE8, // SDPSanax
 
270
        0x00E70D79, // SPxPDxan
 
271
        0x00E81D74, // SSPxDSxax
 
272
        0x00E95CE6, // DSPDSanaxxn
 
273
        0x00EA02E9, // DPSao
 
274
        0x00EB0849, // DPSxno
 
275
        0x00EC02E8, // SDPao
 
276
        0x00ED0848, // SDPxno
 
277
        0x00EE0086, // DSo
 
278
        0x00EF0A08, // SDPnoo
 
279
        0x00F00021, // P
 
280
        0x00F10885, // PDSono
 
281
        0x00F20B05, // PDSnao
 
282
        0x00F3022A, // PSno
 
283
        0x00F40B0A, // PSDnao
 
284
        0x00F50225, // PDno
 
285
        0x00F60265, // PDSxo
 
286
        0x00F708C5, // PDSano
 
287
        0x00F802E5, // PDSao
 
288
        0x00F90845, // PDSxno
 
289
        0x00FA0089, // DPo
 
290
        0x00FB0A09, // DPSnoo
 
291
        0x00FC008A, // PSo
 
292
        0x00FD0A0A, // PSDnoo
 
293
        0x00FE02A9, // DPSoo
 
294
        0x00FF0062  // 1
 
295
};
 
296
 
 
297
static void
 
298
wf_invalidate_region(wfInfo * wfi, int x1, int y1, int x2, int y2)
 
299
{
 
300
        if (wfi->update_pending)
 
301
        {
 
302
                wfi->update_rect.left = min(x1, wfi->update_rect.left);
 
303
                wfi->update_rect.top = min(y1, wfi->update_rect.top);
 
304
                wfi->update_rect.right = max(x2, wfi->update_rect.right);
 
305
                wfi->update_rect.bottom = max(y2, wfi->update_rect.bottom);
 
306
        }
 
307
        else
 
308
        {
 
309
                wfi->update_pending = 1;
 
310
                wfi->update_rect.left = x1;
 
311
                wfi->update_rect.top = y1;
 
312
                wfi->update_rect.right = x2;
 
313
                wfi->update_rect.bottom = y2;
 
314
        }
 
315
}
 
316
 
 
317
static HBITMAP
 
318
wf_create_dib(wfInfo * wfi, int width, int height, int bpp, int reverse, uint8 * data)
 
319
{
 
320
        HBITMAP bitmap;
 
321
        uint8 * cdata;
 
322
        BITMAPINFO bmi = {0};
 
323
        HDC hdc;
 
324
 
 
325
        hdc = GetDC(NULL);
 
326
        bmi.bmiHeader.biSize = sizeof(BITMAPINFO);
 
327
        bmi.bmiHeader.biWidth = width;
 
328
        bmi.bmiHeader.biHeight = height;
 
329
        bmi.bmiHeader.biPlanes = 1;
 
330
        bmi.bmiHeader.biBitCount = 24;
 
331
        bmi.bmiHeader.biCompression = BI_RGB;
 
332
        bitmap = CreateDIBSection (hdc, &bmi, DIB_RGB_COLORS, (void**)&cdata, NULL, 0);
 
333
        if (data != NULL)
 
334
        {
 
335
                wf_image_convert(wfi, width, height, bpp, reverse, data, cdata);
 
336
        }
 
337
        ReleaseDC(NULL, hdc);
 
338
        GdiFlush();
 
339
        return bitmap;
 
340
}
 
341
 
 
342
static HBRUSH
 
343
wf_create_brush(wfInfo * wfi, RD_BRUSH * brush, int color, int bpp)
 
344
{
 
345
        HBRUSH br;
 
346
        LOGBRUSH lbr;
 
347
        HBITMAP pattern = NULL;
 
348
        uint8 * cdata;
 
349
        int i;
 
350
        uint8 ipattern[8];
 
351
 
 
352
        // Style
 
353
        lbr.lbStyle = brush->style;
 
354
        // Color
 
355
        if (lbr.lbStyle == BS_DIBPATTERN || lbr.lbStyle == BS_DIBPATTERN8X8 || lbr.lbStyle == BS_DIBPATTERNPT)
 
356
        {
 
357
                lbr.lbColor = DIB_RGB_COLORS;
 
358
        }
 
359
        else
 
360
        {
 
361
                lbr.lbColor = color;
 
362
        }
 
363
        // Hatch
 
364
        if (lbr.lbStyle == BS_PATTERN || lbr.lbStyle == BS_PATTERN8X8)
 
365
        {
 
366
                if (brush->bd == 0)     /* rdp4 brush */
 
367
                {
 
368
                        for (i = 0; i != 8; i++)
 
369
                        {
 
370
                                ipattern[7 - i] = brush->pattern[i];
 
371
                        }
 
372
                        cdata = wf_glyph_convert(wfi, 8, 8, ipattern);
 
373
                        pattern = CreateBitmap(8, 8, 1, 1, cdata);
 
374
                        lbr.lbHatch = (ULONG_PTR)pattern;
 
375
                        free(cdata);
 
376
                }
 
377
                else if (brush->bd->color_code > 1)     /* > 1 bpp */
 
378
                {
 
379
                        pattern = wf_create_dib(wfi, 8, 8, bpp, 1, brush->bd->data);
 
380
                        lbr.lbHatch = (ULONG_PTR)pattern;
 
381
                }
 
382
                else
 
383
                {
 
384
                        cdata = wf_glyph_convert(wfi, 8, 8, brush->bd->data);
 
385
                        pattern = CreateBitmap(8, 8, 1, 1, cdata);
 
386
                        lbr.lbHatch = (ULONG_PTR)pattern;
 
387
                        free(cdata);
 
388
                }
 
389
        }
 
390
        else if (lbr.lbStyle == BS_HATCHED)
 
391
        {
 
392
                lbr.lbHatch = brush->pattern[0];
 
393
        }
 
394
        else
 
395
        {
 
396
                lbr.lbHatch = 0;
 
397
        }
 
398
 
 
399
        br = CreateBrushIndirect(&lbr);
 
400
        SetBrushOrgEx(wfi->drw->hdc, brush->xorigin, brush->yorigin, NULL);
 
401
        if (pattern != NULL)
 
402
        {
 
403
                DeleteObject(pattern);
 
404
        }
 
405
        return br;
 
406
}
 
407
 
 
408
static struct wf_bitmap *
 
409
wf_bitmap_new(wfInfo * wfi, int width, int height, int bpp, int reverse, uint8 * data)
 
410
{
 
411
        struct wf_bitmap *bm;
 
412
        HDC hdc;
 
413
 
 
414
        hdc = GetDC(NULL);
 
415
        bm = (struct wf_bitmap *) malloc(sizeof(struct wf_bitmap));
 
416
        bm->hdc = CreateCompatibleDC(hdc);
 
417
        if (data == NULL)
 
418
        {
 
419
                bm->bitmap = CreateCompatibleBitmap(hdc, width, height);
 
420
        }
 
421
        else
 
422
        {
 
423
                bm->bitmap = wf_create_dib(wfi, width, height, bpp, reverse, data);
 
424
        }
 
425
        bm->org_bitmap = (HBITMAP)SelectObject(bm->hdc, bm->bitmap);
 
426
        ReleaseDC(NULL, hdc);
 
427
        return bm;
 
428
}
 
429
 
 
430
static void
 
431
wf_bitmap_free(struct wf_bitmap * bm)
 
432
{
 
433
        if (bm != 0)
 
434
        {
 
435
                SelectObject(bm->hdc, bm->org_bitmap);
 
436
                DeleteObject(bm->bitmap);
 
437
                DeleteDC(bm->hdc);
 
438
                free(bm);
 
439
        }
 
440
}
 
441
 
 
442
static void
 
443
l_ui_error(struct rdp_inst * inst, char * text)
 
444
{
 
445
        printf("ui_error: %s", text);
 
446
}
 
447
 
 
448
static void
 
449
l_ui_warning(struct rdp_inst * inst, char * text)
 
450
{
 
451
        printf("ui_warning: %s\n", text);
 
452
}
 
453
 
 
454
static void
 
455
l_ui_unimpl(struct rdp_inst * inst, char * text)
 
456
{
 
457
        printf("ui_unimpl: %s\n", text);
 
458
}
 
459
 
 
460
static void
 
461
l_ui_begin_update(struct rdp_inst * inst)
 
462
{
 
463
        //printf("ui_begin_update\n");
 
464
}
 
465
 
 
466
static void
 
467
l_ui_end_update(struct rdp_inst * inst)
 
468
{
 
469
        //printf("ui_end_update\n");
 
470
}
 
471
 
 
472
static void
 
473
l_ui_desktop_save(struct rdp_inst * inst, int offset, int x, int y,
 
474
        int cx, int cy)
 
475
{
 
476
        printf("ui_desktop_save:\n");
 
477
}
 
478
 
 
479
static void
 
480
l_ui_desktop_restore(struct rdp_inst * inst, int offset, int x, int y,
 
481
        int cx, int cy)
 
482
{
 
483
        printf("ui_desktop_restore:\n");
 
484
}
 
485
 
 
486
static RD_HGLYPH
 
487
l_ui_create_glyph(struct rdp_inst * inst, int width, int height, uint8 * data)
 
488
{
 
489
        wfInfo * wfi;
 
490
        uint8 * cdata;
 
491
        HDC hdc;
 
492
        struct wf_bitmap * bm;
 
493
 
 
494
        wfi = GET_WFI(inst);
 
495
        hdc = GetDC(NULL);
 
496
        bm = (struct wf_bitmap *) malloc(sizeof(struct wf_bitmap));
 
497
        bm->hdc = CreateCompatibleDC(hdc);
 
498
        cdata = wf_glyph_convert(wfi, width, height, data);
 
499
        bm->bitmap = CreateBitmap(width, height, 1, 1, cdata);
 
500
        bm->org_bitmap = (HBITMAP)SelectObject(bm->hdc, bm->bitmap);
 
501
        free(cdata);
 
502
        ReleaseDC(NULL, hdc);
 
503
        return (RD_HGLYPH)bm;
 
504
}
 
505
 
 
506
static void
 
507
l_ui_destroy_glyph(struct rdp_inst * inst, RD_HGLYPH glyph)
 
508
{
 
509
        wf_bitmap_free((struct wf_bitmap *) glyph);
 
510
}
 
511
 
 
512
static RD_HBITMAP
 
513
l_ui_create_bitmap(struct rdp_inst * inst, int width, int height, uint8 * data)
 
514
{
 
515
        wfInfo * wfi;
 
516
        struct wf_bitmap * bm;
 
517
 
 
518
        wfi = GET_WFI(inst);
 
519
        bm = wf_bitmap_new(wfi, width, height, inst->settings->server_depth, 1, data);
 
520
        return (RD_HBITMAP) bm;
 
521
}
 
522
 
 
523
static void
 
524
l_ui_destroy_bitmap(struct rdp_inst * inst, RD_HBITMAP bmp)
 
525
{
 
526
        wf_bitmap_free((struct wf_bitmap *) bmp);
 
527
}
 
528
 
 
529
static void
 
530
l_ui_paint_bitmap(struct rdp_inst * inst, int x, int y, int cx, int cy, int width,
 
531
        int height, uint8 * data)
 
532
{
 
533
        wfInfo * wfi;
 
534
        struct wf_bitmap * bm;
 
535
 
 
536
        wfi = GET_WFI(inst);
 
537
        //printf("ui_paint_bitmap x %d y %d cx %d cy %d width %d height %d\n", x, y, cx, cy, width, height);
 
538
        bm = (struct wf_bitmap *) l_ui_create_bitmap(inst, width, height, data);
 
539
        BitBlt(wfi->backstore->hdc, x, y, cx, cy, bm->hdc, 0, 0, SRCCOPY);
 
540
        wf_bitmap_free(bm);
 
541
        wf_invalidate_region(wfi, x, y, x + cx, y + cy);
 
542
}
 
543
 
 
544
static void
 
545
l_ui_line(struct rdp_inst * inst, uint8 opcode, int startx, int starty, int endx,
 
546
        int endy, RD_PEN * pen)
 
547
{
 
548
        wfInfo * wfi;
 
549
        HPEN hpen;
 
550
        HPEN org_hpen;
 
551
        int color;
 
552
        int org_rop2;
 
553
 
 
554
        wfi = GET_WFI(inst);
 
555
        //printf("ui_line opcode %d startx %d starty %d endx %d endy %d\n", opcode, startx, starty, endx, endy);
 
556
        color = wf_color_convert(wfi, pen->color, inst->settings->server_depth);
 
557
        hpen = CreatePen(pen->style, pen->width, color);
 
558
        org_rop2 = SetROP2(wfi->drw->hdc, opcode + 1);
 
559
        org_hpen = (HPEN)SelectObject(wfi->drw->hdc, hpen);
 
560
        MoveToEx(wfi->drw->hdc, startx, starty, NULL);
 
561
        LineTo(wfi->drw->hdc, endx, endy);
 
562
        SelectObject(wfi->drw->hdc, org_hpen);
 
563
        SetROP2 (wfi->drw->hdc, org_rop2);
 
564
        DeleteObject(hpen);
 
565
        if (wfi->drw == wfi->backstore)
 
566
        {
 
567
                wf_invalidate_region(wfi, min(startx, endx), min(starty, endy), max(startx, endx), max(starty, endy));
 
568
        }
 
569
}
 
570
 
 
571
static void
 
572
l_ui_rect(struct rdp_inst * inst, int x, int y, int cx, int cy, int color)
 
573
{
 
574
        wfInfo * wfi;
 
575
        RECT rect;
 
576
        HBRUSH brush;
 
577
 
 
578
        wfi = GET_WFI(inst);
 
579
        color = wf_color_convert(wfi, color, inst->settings->server_depth);
 
580
        //printf("ui_rect %i %i %i %i %i\n", x, y, cx, cy, color);
 
581
        rect.left = x;
 
582
        rect.top = y;
 
583
        rect.right = x + cx;
 
584
        rect.bottom = y + cy;
 
585
        brush = CreateSolidBrush(color);
 
586
        FillRect(wfi->drw->hdc, &rect, brush);
 
587
        DeleteObject(brush);
 
588
        if (wfi->drw == wfi->backstore)
 
589
        {
 
590
                wf_invalidate_region(wfi, rect.left, rect.top, rect.right, rect.bottom);
 
591
        }
 
592
}
 
593
 
 
594
static void
 
595
l_ui_polygon(struct rdp_inst * inst, uint8 opcode, uint8 fillmode, RD_POINT * point,
 
596
        int npoints, RD_BRUSH * brush, int bgcolor, int fgcolor)
 
597
{
 
598
        printf("ui_polygon:\n");
 
599
}
 
600
 
 
601
static void
 
602
l_ui_polyline(struct rdp_inst * inst, uint8 opcode, RD_POINT * points, int npoints,
 
603
        RD_PEN * pen)
 
604
{
 
605
        wfInfo * wfi;
 
606
        HPEN hpen;
 
607
        HPEN org_hpen;
 
608
        int color;
 
609
        int org_rop2;
 
610
        int i;
 
611
        POINT * ps;
 
612
 
 
613
        wfi = GET_WFI(inst);
 
614
        //printf("ui_polyline opcode %d npoints %d\n", opcode, npoints);
 
615
        color = wf_color_convert(wfi, pen->color, inst->settings->server_depth);
 
616
        hpen = CreatePen(pen->style, pen->width, color);
 
617
        org_rop2 = SetROP2(wfi->drw->hdc, opcode + 1);
 
618
        org_hpen = (HPEN)SelectObject(wfi->drw->hdc, hpen);
 
619
        if (npoints > 0)
 
620
        {
 
621
                ps = (POINT *) malloc(sizeof(POINT) * npoints);
 
622
                for (i = 0; i < npoints; i++)
 
623
                {
 
624
                        //printf("ui_polyline point %d %d %d\n", i, points[i].x, points[i].y);
 
625
                        if (i == 0)
 
626
                        {
 
627
                                ps[i].x = points[i].x;
 
628
                                ps[i].y = points[i].y;
 
629
                        }
 
630
                        else
 
631
                        {
 
632
                                ps[i].x = ps[i - 1].x + points[i].x;
 
633
                                ps[i].y = ps[i - 1].y + points[i].y;
 
634
                        }
 
635
                        if (wfi->drw == wfi->backstore)
 
636
                        {
 
637
                                wf_invalidate_region(wfi, ps[i].x, ps[i].y, ps[i].x + 1, ps[i].y + 1);
 
638
                        }
 
639
                }
 
640
                Polyline(wfi->drw->hdc, ps, npoints);
 
641
        }
 
642
        SelectObject(wfi->drw->hdc, org_hpen);
 
643
        SetROP2 (wfi->drw->hdc, org_rop2);
 
644
        DeleteObject(hpen);
 
645
}
 
646
 
 
647
static void
 
648
l_ui_ellipse(struct rdp_inst * inst, uint8 opcode, uint8 fillmode, int x, int y,
 
649
        int cx, int cy, RD_BRUSH * brush, int bgcolor, int fgcolor)
 
650
{
 
651
        printf("ui_ellipse:\n");
 
652
}
 
653
 
 
654
static void
 
655
l_ui_start_draw_glyphs(struct rdp_inst * inst, int bgcolor, int fgcolor)
 
656
{
 
657
        wfInfo * wfi;
 
658
 
 
659
        wfi = GET_WFI(inst);
 
660
        wfi->brush = CreateSolidBrush(wf_color_convert(wfi, fgcolor, inst->settings->server_depth));
 
661
        wfi->org_brush = (HBRUSH)SelectObject(wfi->drw->hdc, wfi->brush);
 
662
}
 
663
 
 
664
static void
 
665
l_ui_draw_glyph(struct rdp_inst * inst, int x, int y, int cx, int cy,
 
666
        RD_HGLYPH glyph)
 
667
{
 
668
        wfInfo * wfi;
 
669
        struct wf_bitmap * bm;
 
670
 
 
671
        wfi = GET_WFI(inst);
 
672
        bm = (struct wf_bitmap *) glyph;
 
673
        BitBlt(wfi->drw->hdc, x, y, cx, cy, bm->hdc, 0, 0, 0x00E20746); // DSPDxax
 
674
 
 
675
        if (wfi->drw == wfi->backstore)
 
676
        {
 
677
                wf_invalidate_region(wfi, x, y, x + cx, y + cy);
 
678
        }
 
679
}
 
680
 
 
681
static void
 
682
l_ui_end_draw_glyphs(struct rdp_inst * inst, int x, int y, int cx, int cy)
 
683
{
 
684
        wfInfo * wfi;
 
685
 
 
686
        wfi = GET_WFI(inst);
 
687
        SelectObject(wfi->drw->hdc, wfi->org_brush);
 
688
        DeleteObject(wfi->brush);
 
689
        wfi->brush = NULL;
 
690
        wfi->org_brush = NULL;
 
691
}
 
692
 
 
693
static uint32
 
694
l_ui_get_toggle_keys_state(struct rdp_inst * inst)
 
695
{
 
696
        uint32 state = 0;
 
697
 
 
698
        if (GetKeyState(VK_SCROLL))
 
699
        {
 
700
                state |= KBD_SYNC_SCROLL_LOCK;
 
701
        }
 
702
        if (GetKeyState(VK_NUMLOCK))
 
703
        {
 
704
                state |= KBD_SYNC_NUM_LOCK;
 
705
        }
 
706
        if (GetKeyState(VK_CAPITAL))
 
707
        {
 
708
                state |= KBD_SYNC_CAPS_LOCK;
 
709
        }
 
710
        if (GetKeyState(VK_KANA))
 
711
        {
 
712
                state |= KBD_SYNC_KANA_LOCK;
 
713
        }
 
714
        return state;
 
715
}
 
716
 
 
717
static void
 
718
l_ui_bell(struct rdp_inst * inst)
 
719
{
 
720
        MessageBeep(MB_OK);
 
721
}
 
722
 
 
723
static void
 
724
l_ui_destblt(struct rdp_inst * inst, uint8 opcode, int x, int y, int cx, int cy)
 
725
{
 
726
        wfInfo * wfi;
 
727
 
 
728
        wfi = GET_WFI(inst);
 
729
        BitBlt(wfi->drw->hdc, x, y, cx, cy, NULL, 0, 0, rop3_code_table[opcode]);
 
730
        if (wfi->drw == wfi->backstore)
 
731
        {
 
732
                wf_invalidate_region(wfi, x, y, x + cx, y + cy);
 
733
        }
 
734
}
 
735
 
 
736
static void
 
737
l_ui_patblt(struct rdp_inst * inst, uint8 opcode, int x, int y, int cx, int cy,
 
738
        RD_BRUSH * brush, int bgcolor, int fgcolor)
 
739
{
 
740
        wfInfo * wfi;
 
741
        HBRUSH br;
 
742
        HBRUSH org_br;
 
743
        int org_bkmode;
 
744
        COLORREF org_bkcolor;
 
745
        COLORREF org_textcolor;
 
746
 
 
747
        wfi = GET_WFI(inst);
 
748
        //printf("ui_patblt: style %d x %d y %d cx %d cy %d\n", brush->style, x, y, cx, cy);
 
749
        bgcolor = wf_color_convert(wfi, bgcolor, inst->settings->server_depth);
 
750
        fgcolor = wf_color_convert(wfi, fgcolor, inst->settings->server_depth);
 
751
 
 
752
        br = wf_create_brush(wfi, brush, fgcolor, inst->settings->server_depth);
 
753
        org_bkmode = SetBkMode(wfi->drw->hdc, OPAQUE);
 
754
        org_bkcolor = SetBkColor(wfi->drw->hdc, bgcolor);
 
755
        org_textcolor = SetTextColor(wfi->drw->hdc, fgcolor);
 
756
        org_br = (HBRUSH)SelectObject(wfi->drw->hdc, br);
 
757
        PatBlt(wfi->drw->hdc, x, y, cx, cy, rop3_code_table[opcode]);
 
758
        SelectObject(wfi->drw->hdc, org_br);
 
759
        DeleteObject(br);
 
760
        SetBkMode(wfi->drw->hdc, org_bkmode);
 
761
        SetBkColor(wfi->drw->hdc, org_bkcolor);
 
762
        SetTextColor(wfi->drw->hdc, org_textcolor);
 
763
        if (wfi->drw == wfi->backstore)
 
764
        {
 
765
                wf_invalidate_region(wfi, x, y, x + cx, y + cy);
 
766
        }
 
767
}
 
768
 
 
769
static void
 
770
l_ui_screenblt(struct rdp_inst * inst, uint8 opcode, int x, int y, int cx, int cy,
 
771
        int srcx, int srcy)
 
772
{
 
773
        wfInfo * wfi;
 
774
 
 
775
        wfi = GET_WFI(inst);
 
776
        //printf("ui_screenblt: opcode %d x %d y %d cx %d cy %d srcx %d srcy%d \n", opcode, x, y, cx, cy, srcx, srcy);
 
777
        BitBlt(wfi->drw->hdc, x, y, cx, cy, wfi->backstore->hdc, srcx, srcy, rop3_code_table[opcode]);
 
778
        if (wfi->drw == wfi->backstore)
 
779
        {
 
780
                wf_invalidate_region(wfi, x, y, x + cx, y + cy);
 
781
        }
 
782
}
 
783
 
 
784
static void
 
785
l_ui_memblt(struct rdp_inst * inst, uint8 opcode, int x, int y, int cx, int cy,
 
786
        RD_HBITMAP src, int srcx, int srcy)
 
787
{
 
788
        wfInfo * wfi;
 
789
        struct wf_bitmap * bm;
 
790
 
 
791
        wfi = GET_WFI(inst);
 
792
        bm = (struct wf_bitmap *) src;
 
793
        //printf("ui_memblt %i %i %i %i %i %i %i\n", x, y, cx, cy, srcx, srcy, opcode);
 
794
        BitBlt(wfi->drw->hdc, x, y, cx, cy, bm->hdc, srcx, srcy, rop3_code_table[opcode]);
 
795
        if (wfi->drw == wfi->backstore)
 
796
        {
 
797
                wf_invalidate_region(wfi, x, y, x + cx, y + cy);
 
798
        }
 
799
}
 
800
 
 
801
static void
 
802
l_ui_triblt(struct rdp_inst * inst, uint8 opcode, int x, int y, int cx, int cy,
 
803
        RD_HBITMAP src, int srcx, int srcy, RD_BRUSH * brush, int bgcolor, int fgcolor)
 
804
{
 
805
        wfInfo * wfi;
 
806
 
 
807
        wfi = GET_WFI(inst);
 
808
        printf("ui_triblt\n");
 
809
        //TODO
 
810
}
 
811
 
 
812
static int
 
813
l_ui_select(struct rdp_inst * inst, int rdp_socket)
 
814
{
 
815
        //printf("ui_select: inst %p\n", inst);
 
816
        return 1;
 
817
}
 
818
 
 
819
static void
 
820
l_ui_set_clip(struct rdp_inst * inst, int x, int y, int cx, int cy)
 
821
{
 
822
        wfInfo * wfi;
 
823
        HRGN hrgn;
 
824
 
 
825
        wfi = GET_WFI(inst);
 
826
        //printf("ui_set_clip %i %i %i %i\n", x, y, cx, cy);
 
827
        hrgn = CreateRectRgn(x, y, x + cx, y + cy);
 
828
        SelectClipRgn(wfi->drw->hdc, hrgn);
 
829
        DeleteObject(hrgn);
 
830
}
 
831
 
 
832
static void
 
833
l_ui_reset_clip(struct rdp_inst * inst)
 
834
{
 
835
        wfInfo * wfi;
 
836
 
 
837
        wfi = GET_WFI(inst);
 
838
        //printf("ui_reset_clip\n");
 
839
        SelectClipRgn(wfi->drw->hdc, NULL);
 
840
}
 
841
 
 
842
static void
 
843
l_ui_resize_window(struct rdp_inst * inst)
 
844
{
 
845
        printf("ui_resize_window:\n");
 
846
}
 
847
 
 
848
static void
 
849
l_ui_set_cursor(struct rdp_inst * inst, RD_HCURSOR cursor)
 
850
{
 
851
        wfInfo * wfi;
 
852
 
 
853
        wfi = GET_WFI(inst);
 
854
        wfi->cursor = (HCURSOR)cursor;
 
855
        PostMessage(wfi->hwnd, WM_SETCURSOR, 0, 0);
 
856
}
 
857
 
 
858
static void
 
859
l_ui_destroy_cursor(struct rdp_inst * inst, RD_HCURSOR cursor)
 
860
{
 
861
        wfInfo * wfi;
 
862
 
 
863
        wfi = GET_WFI(inst);
 
864
        if (wfi->cursor == (HCURSOR)cursor)
 
865
        {
 
866
                wfi->cursor = g_default_cursor;
 
867
                PostMessage(wfi->hwnd, WM_SETCURSOR, 0, 0);
 
868
        }
 
869
        DestroyCursor((HCURSOR)cursor);
 
870
}
 
871
 
 
872
static RD_HCURSOR
 
873
l_ui_create_cursor(struct rdp_inst * inst, uint32 x, uint32 y,
 
874
        int width, int height, uint8 * andmask, uint8 * xormask, int bpp)
 
875
{
 
876
        wfInfo * wfi;
 
877
        HCURSOR cursor;
 
878
        ICONINFO iconinfo;
 
879
        uint8 * cdata;
 
880
 
 
881
        wfi = GET_WFI(inst);
 
882
        if (bpp == 1)
 
883
        {
 
884
                cursor = CreateCursor(g_hInstance, x, y, width, height, andmask, xormask);
 
885
        }
 
886
        else
 
887
        {
 
888
                iconinfo.fIcon = FALSE;
 
889
                iconinfo.xHotspot = x;
 
890
                iconinfo.yHotspot = y;
 
891
                cdata = wf_cursor_mask_convert(wfi, width, height, andmask);
 
892
                iconinfo.hbmMask = CreateBitmap(width, height, 1, 1, cdata);
 
893
                iconinfo.hbmColor = wf_create_dib(wfi, width, height, bpp, 0, xormask);
 
894
                cursor = CreateIconIndirect(&iconinfo);
 
895
                DeleteObject(iconinfo.hbmMask);
 
896
                DeleteObject(iconinfo.hbmColor);
 
897
                free(cdata);
 
898
        }
 
899
        return (RD_HCURSOR)cursor;
 
900
}
 
901
 
 
902
static void
 
903
l_ui_set_null_cursor(struct rdp_inst * inst)
 
904
{
 
905
        wfInfo * wfi;
 
906
 
 
907
        wfi = GET_WFI(inst);
 
908
        wfi->cursor = NULL;
 
909
        PostMessage(wfi->hwnd, WM_SETCURSOR, 0, 0);
 
910
}
 
911
 
 
912
static void
 
913
l_ui_set_default_cursor(struct rdp_inst * inst)
 
914
{
 
915
        wfInfo * wfi;
 
916
 
 
917
        wfi = GET_WFI(inst);
 
918
        wfi->cursor = g_default_cursor;
 
919
        PostMessage(wfi->hwnd, WM_SETCURSOR, 0, 0);
 
920
}
 
921
 
 
922
static RD_HPALETTE
 
923
l_ui_create_colormap(struct rdp_inst * inst, RD_PALETTE * colors)
 
924
{
 
925
        wfInfo * wfi;
 
926
 
 
927
        wfi = GET_WFI(inst);
 
928
        return wf_create_colormap(wfi, colors);
 
929
}
 
930
 
 
931
static void
 
932
l_ui_move_pointer(struct rdp_inst * inst, int x, int y)
 
933
{
 
934
        wfInfo * wfi;
 
935
 
 
936
        wfi = GET_WFI(inst);
 
937
        //TODO
 
938
}
 
939
 
 
940
static void
 
941
l_ui_set_colormap(struct rdp_inst * inst, RD_HPALETTE map)
 
942
{
 
943
        wfInfo * wfi;
 
944
 
 
945
        wfi = GET_WFI(inst);
 
946
        wf_set_colormap(wfi, map);
 
947
}
 
948
 
 
949
static RD_HBITMAP
 
950
l_ui_create_surface(struct rdp_inst * inst, int width, int height, RD_HBITMAP old_surface)
 
951
{
 
952
        wfInfo * wfi;
 
953
        struct wf_bitmap * bm;
 
954
        struct wf_bitmap * old_bm;
 
955
 
 
956
        wfi = GET_WFI(inst);
 
957
        bm = wf_bitmap_new(wfi, width, height, 0, 0, NULL);
 
958
        old_bm = (struct wf_bitmap *) old_surface;
 
959
        if (old_bm != 0)
 
960
        {
 
961
                BitBlt(bm->hdc, 0, 0, width, height, old_bm->hdc, 0, 0, SRCCOPY);
 
962
                wf_bitmap_free(old_bm);
 
963
        }
 
964
        if (wfi->drw == old_bm)
 
965
        {
 
966
                wfi->drw = bm;
 
967
        }
 
968
        return (RD_HBITMAP)bm;
 
969
}
 
970
 
 
971
static void
 
972
l_ui_set_surface(struct rdp_inst * inst, RD_HBITMAP surface)
 
973
{
 
974
        wfInfo * wfi;
 
975
 
 
976
        wfi = GET_WFI(inst);
 
977
        if (surface != 0)
 
978
        {
 
979
                wfi->drw = (struct wf_bitmap *) surface;
 
980
        }
 
981
        else
 
982
        {
 
983
                wfi->drw = wfi->backstore;
 
984
        }
 
985
}
 
986
 
 
987
static void
 
988
l_ui_destroy_surface(struct rdp_inst * inst, RD_HBITMAP surface)
 
989
{
 
990
        wfInfo * wfi;
 
991
 
 
992
        wfi = GET_WFI(inst);
 
993
        if (wfi->drw == surface)
 
994
        {
 
995
                l_ui_warning(inst, "ui_destroy_surface: freeing active surface!\n");
 
996
                wfi->drw = wfi->backstore;
 
997
        }
 
998
        if (surface != 0)
 
999
        {
 
1000
                wf_bitmap_free((struct wf_bitmap *)surface);
 
1001
        }
 
1002
}
 
1003
 
 
1004
static void
 
1005
l_ui_channel_data(struct rdp_inst * inst, int chan_id, char * data, int data_size,
 
1006
        int flags, int total_size)
 
1007
{
 
1008
        //TODO
 
1009
}
 
1010
 
 
1011
static int
 
1012
wf_assign_callbacks(rdpInst * inst)
 
1013
{
 
1014
        inst->ui_error = l_ui_error;
 
1015
        inst->ui_warning = l_ui_warning;
 
1016
        inst->ui_unimpl = l_ui_unimpl;
 
1017
        inst->ui_begin_update = l_ui_begin_update;
 
1018
        inst->ui_end_update = l_ui_end_update;
 
1019
        inst->ui_desktop_save = l_ui_desktop_save;
 
1020
        inst->ui_desktop_restore = l_ui_desktop_restore;
 
1021
        inst->ui_create_bitmap = l_ui_create_bitmap;
 
1022
        inst->ui_paint_bitmap = l_ui_paint_bitmap;
 
1023
        inst->ui_destroy_bitmap = l_ui_destroy_bitmap;
 
1024
        inst->ui_line = l_ui_line;
 
1025
        inst->ui_rect = l_ui_rect;
 
1026
        inst->ui_polygon = l_ui_polygon;
 
1027
        inst->ui_polyline = l_ui_polyline;
 
1028
        inst->ui_ellipse = l_ui_ellipse;
 
1029
        inst->ui_start_draw_glyphs = l_ui_start_draw_glyphs;
 
1030
        inst->ui_draw_glyph = l_ui_draw_glyph;
 
1031
        inst->ui_end_draw_glyphs = l_ui_end_draw_glyphs;
 
1032
        inst->ui_get_toggle_keys_state = l_ui_get_toggle_keys_state;
 
1033
        inst->ui_bell = l_ui_bell;
 
1034
        inst->ui_destblt = l_ui_destblt;
 
1035
        inst->ui_patblt = l_ui_patblt;
 
1036
        inst->ui_screenblt = l_ui_screenblt;
 
1037
        inst->ui_memblt = l_ui_memblt;
 
1038
        inst->ui_triblt = l_ui_triblt;
 
1039
        inst->ui_create_glyph = l_ui_create_glyph;
 
1040
        inst->ui_destroy_glyph = l_ui_destroy_glyph;
 
1041
        inst->ui_select = l_ui_select;
 
1042
        inst->ui_set_clip = l_ui_set_clip;
 
1043
        inst->ui_reset_clip = l_ui_reset_clip;
 
1044
        inst->ui_resize_window = l_ui_resize_window;
 
1045
        inst->ui_set_cursor = l_ui_set_cursor;
 
1046
        inst->ui_destroy_cursor = l_ui_destroy_cursor;
 
1047
        inst->ui_create_cursor = l_ui_create_cursor;
 
1048
        inst->ui_set_null_cursor = l_ui_set_null_cursor;
 
1049
        inst->ui_set_default_cursor = l_ui_set_default_cursor;
 
1050
        inst->ui_create_colormap = l_ui_create_colormap;
 
1051
        inst->ui_move_pointer = l_ui_move_pointer;
 
1052
        inst->ui_set_colormap = l_ui_set_colormap;
 
1053
        inst->ui_create_surface = l_ui_create_surface;
 
1054
        inst->ui_set_surface = l_ui_set_surface;
 
1055
        inst->ui_destroy_surface = l_ui_destroy_surface;
 
1056
        inst->ui_channel_data = l_ui_channel_data;
 
1057
        return 0;
 
1058
}
 
1059
 
 
1060
int
 
1061
wf_pre_connect(rdpInst * inst, HWND hwnd)
 
1062
{
 
1063
        wfInfo * wfi;
 
1064
 
 
1065
        wf_assign_callbacks(inst);
 
1066
        wfi = (wfInfo *) malloc(sizeof(wfInfo));
 
1067
        SET_WFI(inst, wfi);
 
1068
        memset(wfi, 0, sizeof(wfInfo));
 
1069
 
 
1070
        wfi->hwnd = hwnd;
 
1071
        wfi->inst = inst;
 
1072
        wfi->cursor = g_default_cursor;
 
1073
        SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)wfi);
 
1074
 
 
1075
        return 0;
 
1076
}
 
1077
 
 
1078
int
 
1079
wf_post_connect(rdpInst * inst)
 
1080
{
 
1081
        wfInfo * wfi;
 
1082
        int width;
 
1083
        int height;
 
1084
        RECT rc_client, rc_wnd;
 
1085
        POINT diff;
 
1086
 
 
1087
        wfi = GET_WFI(inst);
 
1088
        width = inst->settings->width;
 
1089
        height = inst->settings->height;
 
1090
 
 
1091
        wfi->backstore = wf_bitmap_new(wfi, width, height, 0, 0, NULL);
 
1092
        BitBlt(wfi->backstore->hdc, 0, 0, width, height, NULL, 0, 0, BLACKNESS);
 
1093
        wfi->drw = wfi->backstore;
 
1094
 
 
1095
        GetClientRect(wfi->hwnd, &rc_client);
 
1096
        GetWindowRect(wfi->hwnd, &rc_wnd);
 
1097
        diff.x = (rc_wnd.right - rc_wnd.left) - rc_client.right;
 
1098
        diff.y = (rc_wnd.bottom - rc_wnd.top) - rc_client.bottom;
 
1099
        MoveWindow(wfi->hwnd, rc_wnd.left, rc_wnd.top, width + diff.x, height + diff.y, FALSE);
 
1100
        ShowWindow(wfi->hwnd, SW_SHOWNORMAL);
 
1101
        UpdateWindow(wfi->hwnd);
 
1102
 
 
1103
        return 0;
 
1104
}
 
1105
 
 
1106
int
 
1107
wf_update_window(rdpInst * inst)
 
1108
{
 
1109
        wfInfo * wfi;
 
1110
 
 
1111
        wfi = GET_WFI(inst);
 
1112
        if (wfi->update_pending)
 
1113
        {
 
1114
                InvalidateRect(wfi->hwnd, &wfi->update_rect, FALSE);
 
1115
                wfi->update_pending = 0;
 
1116
                return 1;
 
1117
        }
 
1118
        return 0;
 
1119
}
 
1120
 
 
1121
void
 
1122
wf_uninit(rdpInst * inst)
 
1123
{
 
1124
        wfInfo * wfi;
 
1125
 
 
1126
        wfi = GET_WFI(inst);
 
1127
        /* Inform the main thread to destroy the window */
 
1128
        SetWindowLongPtr(wfi->hwnd, GWLP_USERDATA, -1);
 
1129
        CloseWindow(wfi->hwnd);
 
1130
        wf_bitmap_free(wfi->backstore);
 
1131
        if (wfi->colormap != 0)
 
1132
        {
 
1133
                free(wfi->colormap);
 
1134
        }
 
1135
        free(wfi);
 
1136
}