OpenCores
URL https://opencores.org/ocsvn/openrisc_me/openrisc_me/trunk

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [rtos/] [ecos-2.0/] [packages/] [services/] [gfx/] [mw/] [v2_0/] [include/] [microwin/] [mwobjects.h] - Blame information for rev 174

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 27 unneback
/*
2
  Copyright (C) Chris Johns (ccj@acm.org)
3
 
4
  MicroWindows C++ Wrappers.
5
 
6
 */
7
 
8
#if !defined (_MWOBJECTS_H_)
9
#define _MWOBJECTS_H_
10
 
11
extern "C"
12
{
13
#include "windows.h"
14
#include "wintern.h"
15
#include "graph3d.h"
16
};
17
 
18
#include <set>
19
#include <iostream>
20
 
21
namespace MicroWindowsObjects
22
{
23
  class FileDescriptor;
24
 
25
  //
26
  // Manage Window Classes. Notice you do not need to specify
27
  // a Window Procedure function pointer. This is handled for 
28
  // you.
29
  //
30
 
31
  class WindowClass
32
  {
33
  public:
34
 
35
    WindowClass ();
36
    WindowClass (LPCSTR    lpszClassName,
37
                 UINT      style = CS_DBLCLKS | CS_VREDRAW | CS_HREDRAW,
38
                 int       cbClsExtra = 0,
39
                 int       cbWndExtra = 0,
40
                 HINSTANCE hInstance = 0,
41
                 HICON     hIcon = 0,
42
                 HCURSOR   hCursor = 0,
43
                 HBRUSH    hbrBackground = 0,
44
                 LPCSTR    lpszMenuName = 0);
45
 
46
    void set_style (UINT style)
47
      { wclass.style = style; }
48
 
49
    void set_class_extra (int cbClsExtra)
50
      { wclass.cbClsExtra = cbClsExtra; }
51
 
52
    void set_window_extra (int cbWndExtra)
53
      { wclass.cbWndExtra = cbWndExtra; }
54
 
55
    void set_instance (HINSTANCE hInstance)
56
      { wclass.hInstance = hInstance; }
57
 
58
    void set_icon (HICON hIcon)
59
      { wclass.hIcon = hIcon; }
60
 
61
    void set_cursor (HCURSOR hCursor)
62
      { wclass.hCursor = hCursor; }
63
 
64
    void set_background (HBRUSH hbrBackground)
65
      { wclass.hbrBackground = hbrBackground; }
66
 
67
    void set_menu_name (LPCSTR lpszMenuName)
68
      { wclass.lpszMenuName = lpszMenuName; }
69
 
70
    ATOM register_class ();
71
 
72
  private:
73
 
74
    //
75
    // This variable is a local copy which is 
76
    // registered. After that is class does little.
77
    //
78
 
79
    WNDCLASS wclass;
80
  };
81
 
82
  class Window
83
  {
84
    friend WindowClass;
85
 
86
  public:
87
 
88
    Window ();
89
    Window (DWORD     dwExStyle,
90
            LPCSTR    lpClassName,
91
            LPCSTR    lpWindowName,
92
            DWORD     dwStyle,
93
            int       x,
94
            int       y,
95
            int       nWidth,
96
            int       nHeight,
97
            HWND      hwndParent,
98
            HMENU     hMenu,
99
            HINSTANCE hInstance,
100
            LPVOID    lpParam);
101
 
102
    virtual ~Window ();
103
 
104
    HWND create (DWORD     dwExStyle,
105
                 LPCSTR    lpClassName,
106
                 LPCSTR    lpWindowName,
107
                 DWORD     dwStyle,
108
                 int       x,
109
                 int       y,
110
                 int       nWidth,
111
                 int       nHeight,
112
                 HWND      hwndParent,
113
                 HMENU     hMenu,
114
                 HINSTANCE hInstance,
115
                 LPVOID    lpParam);
116
 
117
    BOOL destory ();
118
 
119
    HWND get_handle () const
120
      { return hwnd; }
121
    operator HWND () const
122
      { return get_handle (); }
123
 
124
    BOOL is_visible ()
125
      { return IsWindowVisible (hwnd); }
126
    BOOL show (int nCmdShow)
127
      { return ::ShowWindow (hwnd, nCmdShow); }
128
    BOOL update ()
129
      { return ::UpdateWindow (hwnd); }
130
    BOOL invalidate_rect (CONST RECT *lpRect, BOOL bErase)
131
      { return ::InvalidateRect (hwnd, lpRect, bErase); }
132
 
133
    HWND get_focus ()
134
      { return ::GetFocus (); }
135
    HWND set_focus ()
136
      { return ::SetFocus (hwnd); }
137
 
138
    BOOL move (int x, int y, int nWidth, int nHeight, BOOL bRepaint)
139
      { return MoveWindow (hwnd, x, y, nWidth, nHeight, bRepaint); }
140
 
141
    // FIXME: Should these be here ?
142
    BOOL client_to_screen (LPPOINT lpPoint)
143
      { return ::ClientToScreen (hwnd, lpPoint); }
144
    BOOL screen_to_client (LPPOINT lpPoint)
145
      { return ::ClientToScreen (hwnd, lpPoint); }
146
 
147
    LONG get_long (int nIndex)
148
      { return ::GetWindowLong (hwnd, nIndex); }
149
    LONG set_long (int nIndex, LONG wNewLong)
150
      { return ::SetWindowWord (hwnd, nIndex, wNewLong); }
151
    WORD get_word (int nIndex)
152
      { return ::GetWindowWord (hwnd, nIndex); }
153
    WORD set_word (int nIndex, WORD wNewWord)
154
      { return ::SetWindowWord (hwnd, nIndex, wNewWord); }
155
 
156
    DWORD get_class_long (int nIndex)
157
      { return ::GetClassLong (hwnd, nIndex); }
158
 
159
    int get_text (LPSTR lpString, int nMaxCount)
160
      { return GetWindowText (hwnd, lpString, nMaxCount); }
161
    BOOL set_text (LPCSTR lpString)
162
      { return SetWindowText (hwnd, lpString); }
163
 
164
    //
165
    // File Descriptor handlers.
166
    //
167
 
168
    virtual bool attach (const int fd, FileDescriptor& file_descriptor);
169
    virtual bool detach (FileDescriptor& file_descriptor);
170
 
171
  protected:
172
 
173
    //
174
    // The message handler. Insure you call this class's default
175
    // handler for default message handling so any special
176
    // filtering can occur.
177
    //
178
 
179
    virtual LRESULT message_handler (UINT   msg,
180
                                     WPARAM wParam,
181
                                     LPARAM lParam);
182
 
183
  private:
184
 
185
    //
186
    // We only need one WndProc.
187
    //
188
 
189
    static LRESULT CALLBACK WndProc (HWND hwnd, UINT msg, WPARAM wp, LPARAM lp);
190
 
191
    HWND   hwnd;
192
    LPVOID lpCreateParams;
193
 
194
    //
195
    // Set of FileDescriptor objects
196
    //
197
 
198
    struct ltint
199
    {
200
      bool operator() (const FileDescriptor* f1, const FileDescriptor* f2) const;
201
    };
202
 
203
    set<FileDescriptor*, ltint> file_descriptors;
204
 
205
  };
206
 
207
  class Rect
208
  {
209
  public:
210
 
211
    Rect ()
212
      { empty (); }
213
    Rect (int xLeft, int yTop, int xRight, int yBottom)
214
      { set (xLeft, yTop, xRight, yBottom); }
215
    Rect (HWND hwnd)
216
      { get_window (hwnd); }
217
 
218
    BOOL get_window (HWND hwnd)
219
       { return GetWindowRect (hwnd, &rect); }
220
    BOOL get_client (HWND hwnd)
221
       { return GetClientRect (hwnd, &rect); }
222
 
223
    BOOL set (int xLeft, int yTop, int xRight, int yBottom)
224
      { return ::SetRect (&rect, xLeft, yTop, xRight, yBottom); }
225
 
226
    BOOL empty ()
227
      { return ::SetRectEmpty (&rect); }
228
 
229
    Rect& operator= (const Rect& other)
230
      { CopyRect (&rect, &other.rect); return *this; }
231
 
232
    operator bool () const
233
      { return ::IsRectEmpty (&rect); }
234
 
235
    operator RECT* ()
236
      { return &rect; }
237
 
238
    BOOL copy (LPRECT lpRectDst)
239
      { return ::CopyRect (lpRectDst, &rect); }
240
 
241
    BOOL inflate (int dx, int dy)
242
      { return ::InflateRect (&rect, dx, dy); }
243
 
244
    BOOL offset (int dx, int dy)
245
      { return ::OffsetRect (&rect, dx, dy); }
246
 
247
    BOOL point_inside (POINT Point)
248
      { return PtInRect (&rect, Point); }
249
 
250
    MWCOORD left () const
251
      { return rect.left; }
252
    MWCOORD top () const
253
      { return rect.top; }
254
    MWCOORD right () const
255
      { return rect.right; }
256
    MWCOORD bottom () const
257
      { return rect.bottom; }
258
 
259
  private:
260
 
261
    RECT rect;
262
  };
263
 
264
  inline ostream& operator<< (ostream& s, const Rect& r) {
265
    s << "rect"
266
      << "(l=" << r.left ()  << ",t=" << r.top ()
267
      << ",r=" << r.right () << ",b=" << r.bottom ()
268
      << ")";
269
    return s;
270
  }
271
 
272
  //
273
  // Generic Paint class. Try to help the paint message.
274
  //
275
 
276
  class Paint
277
  {
278
  public:
279
 
280
    enum { TEXT_BUF_SIZE = 512 };
281
 
282
    Paint (HWND hwnd);
283
    Paint (HWND hwnd, LPARAM lpParam);
284
    virtual ~Paint ();
285
 
286
    //
287
    // These begin and end a paint session.
288
    //
289
 
290
    void begin (bool init_3d = false, bool draw_3d_in_memory = false);
291
    void end ();
292
 
293
    //
294
    // Aspects of the client paint area under our control.
295
    //
296
 
297
    operator HWND ()
298
      { return hwnd; }
299
    operator RECT* ()
300
      { return r; }
301
    operator HDC ()
302
      { return hdc; }
303
    operator PAINTSTRUCT* ()
304
      { return &ps; }
305
    operator POINT* ()
306
      { return &pt; }
307
 
308
    GDICOORD get_point_x () const
309
      { return pt.x; }
310
    GDICOORD get_point_y () const
311
      { return pt.y; }
312
 
313
    MWCOORD left () const
314
      { return r.left (); }
315
    MWCOORD top () const
316
      { return r.top (); }
317
    MWCOORD right () const
318
      { return r.right (); }
319
    MWCOORD bottom () const
320
      { return r.bottom (); }
321
 
322
    //
323
    // Colour Control.
324
    //
325
 
326
    DWORD get_system_colour (int nIndex)
327
      { return ::GetSysColor (nIndex); }
328
 
329
    //
330
    // Pixel, line and rectange draw support.
331
    //
332
 
333
    COLORREF set_pixel (int x, int y, COLORREF crColour)
334
      { return ::SetPixel (hdc, x, y, crColour); }
335
 
336
    BOOL move_to (int x, int y)
337
      { return ::MoveToEx (hdc, x, y, 0); }
338
 
339
    BOOL line_to (int x, int y)
340
      { return ::LineTo (hdc, x, y); }
341
 
342
    BOOL line_to (int x1, int y1, int x2, int y2)
343
      { if (!move_to (x1, y1)) return FALSE;
344
        return line_to (x2, y2); }
345
 
346
    BOOL rectangle (int x1, int y1, int x2, int y2)
347
      { return ::Rectangle (hdc, x1, y1, x2, y2); }
348
 
349
    BOOL fill_rectangle (int x1, int y1, int x2, int y2, HBRUSH hbr)
350
      { Rect r (x1, y1, x2, y2);
351
        return ::FillRect (hdc, r, hbr); }
352
 
353
    //
354
    // Paint any 3d objects.
355
    //
356
 
357
    void initialise_3d (bool draw_3d_in_mem)
358
      { if (!draw_3d) {
359
        draw_3d = true; ::init3 (hdc, draw_3d_in_mem ? hwnd : 0); } }
360
    void paint_3d ()
361
      { if (draw_3d) { ::paint3 (hdc); draw_3d = false; } }
362
 
363
    //
364
    // Text Output.
365
    //
366
 
367
    void set_text_fromat (UINT uFormat)
368
       { text_format = uFormat; }
369
 
370
    int text_out (int x, int y, const char *format, ...);
371
 
372
  private:
373
 
374
    HWND        hwnd;
375
    bool        draw_3d;
376
    bool        drawing;
377
    Rect        r;
378
    HDC         hdc;
379
    PAINTSTRUCT ps;
380
    POINT       pt;
381
    UINT        text_format;
382
 
383
    char        format_buf[TEXT_BUF_SIZE];
384
 
385
  };
386
 
387
  //
388
  // FileDescriptor handles fd event from the  User Registered File 
389
  // Descriptor support.
390
  //
391
 
392
  class FileDescriptor
393
  {
394
    friend class Window;
395
 
396
  public:
397
 
398
    FileDescriptor ();
399
    virtual ~FileDescriptor ();
400
 
401
    //
402
    // Enable/disable controls.
403
    //
404
 
405
    bool enable_read ();
406
    bool disable_read ();
407
    bool read_enabled () const
408
      { return read_is_enabled; }
409
 
410
    bool enable_write ();
411
    bool disable_write ();
412
    bool write_enabled () const
413
      { return write_is_enabled; }
414
 
415
    bool enable_except ();
416
    bool disable_except ();
417
    bool except_enabled () const
418
      { return except_is_enabled; }
419
 
420
    int fd () const
421
      { return file_desc; }
422
 
423
    operator int () const
424
      { return fd (); }
425
 
426
    const Window *get_window () const
427
      { return window; }
428
 
429
  protected:
430
 
431
    //
432
    // These are called in responce to user fd messages to the window.
433
    //
434
 
435
    virtual LRESULT read ();
436
    virtual LRESULT write ();
437
    virtual LRESULT except ();
438
 
439
  private:
440
 
441
    int    file_desc;
442
    bool   read_is_enabled;
443
    bool   write_is_enabled;
444
    bool   except_is_enabled;
445
    Window *window;
446
 
447
  };
448
 
449
  class Application
450
  {
451
  public:
452
 
453
    Application ();
454
    Application (MWIMAGEHDR& background);
455
    virtual ~Application ();
456
 
457
    HINSTANCE instance () const
458
      { return app_instance; }
459
 
460
    HINSTANCE prev_instance () const
461
      { return app_prev_instance; }
462
 
463
    LPSTR cmd_line () const
464
      { return app_cmd_line; }
465
 
466
    int show_cmd ()
467
      { return app_show_cmd; }
468
 
469
    //
470
    // This is called the public C linkage WinMain. Do not call.
471
    //
472
 
473
    static int WINAPI WinMain (HINSTANCE hInstance,
474
                               HINSTANCE hPrevInstance,
475
                               LPSTR     lpCmdLine,
476
                               int       nShowCmd);
477
  protected:
478
 
479
    virtual int initialise ();
480
    virtual int shutdown ();
481
 
482
  private:
483
 
484
    MWIMAGEHDR  *background;
485
    HINSTANCE app_instance;
486
    HINSTANCE app_prev_instance;
487
    LPSTR     app_cmd_line;
488
    int       app_show_cmd;
489
 
490
  };
491
}
492
 
493
#endif
494
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.