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

Subversion Repositories or1k

[/] [or1k/] [tags/] [MW_0_8_9PRE7/] [mw/] [src/] [mwin/] [winlib/] [static.c] - Blame information for rev 674

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 673 markom
/*
2
 * Copyright (C) 1999, 2000, Wei Yongming.
3
 * Portions Copyright (c) 2000 Greg Haerr <greg@censoft.com>
4
 *
5
 * Static control for Microwindows win32 api.
6
 */
7
 
8
/*
9
**  This library is free software; you can redistribute it and/or
10
**  modify it under the terms of the GNU Library General Public
11
**  License as published by the Free Software Foundation; either
12
**  version 2 of the License, or (at your option) any later version.
13
**
14
**  This library is distributed in the hope that it will be useful,
15
**  but WITHOUT ANY WARRANTY; without even the implied warranty of
16
**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17
**  Library General Public License for more details.
18
**
19
**  You should have received a copy of the GNU Library General Public
20
**  License along with this library; if not, write to the Free
21
**  Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
22
**  MA 02111-1307, USA
23
*/
24
 
25
/*
26
**  Alternatively, the contents of this file may be used under the terms
27
**  of the Mozilla Public License (the "MPL License") in which case the
28
**  provisions of the MPL License are applicable instead of those above.
29
*/
30
 
31
/* Create date: 1999/5/22
32
**
33
** Modify records:
34
**
35
**  Who             When        Where       For What                Status
36
**-----------------------------------------------------------------------------
37
**  WEI Yongming    1999/8/21   Tsinghua    Rearrangment            Finished
38
**  WEI Yongming    1999/10/27  Tsinghua    SETTEXT bug             Finished
39
**  WEI Yongming    1999/10/27  Tsinghua    SETTEXT bug             Finished
40
**  WEI Yongming    2000/02/24  Tsinghua    Add MPL License         Finished
41
**  Kevin Tseng     2000/06/26  gv          port to microwin        ported
42
**  Greg Haerr      2000/07/05  Utah        bug fixes               Finished
43
*/
44
 
45
#include <stdio.h>
46
#include <stdlib.h>
47
#include <string.h>
48
#define MWINCLUDECOLORS
49
#include "windows.h"    /* windef.h, winuser.h */
50
#include "wintools.h"
51
#include "device.h"     /* GdGetTextSize */
52
 
53
/* jmt: should be SYSTEM_FIXED_FONT because of minigui's GetSysCharXXX() */
54
#define FONT_NAME       SYSTEM_FIXED_FONT       /* was DEFAULT_GUI_FONT*/
55
 
56
static LRESULT CALLBACK
57
StaticControlProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
58
 
59
int WINAPI MwRegisterStaticControl(HINSTANCE hInstance)
60
{
61
        WNDCLASS        wc;
62
 
63
        wc.style        = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS | CS_GLOBALCLASS;
64
        wc.lpfnWndProc  = (WNDPROC)StaticControlProc;
65
        wc.cbClsExtra   = 0;
66
        wc.cbWndExtra   = 0;
67
        wc.hInstance    = hInstance;
68
        wc.hIcon        = NULL;
69
        wc.hCursor      = 0; /*LoadCursor(NULL, IDC_ARROW);*/
70
        wc.hbrBackground= GetStockObject(WHITE_BRUSH);
71
        wc.lpszMenuName = NULL;
72
        wc.lpszClassName= "STATIC";
73
 
74
        return RegisterClass(&wc);
75
}
76
 
77
#if 1
78
#define RECTW(rc) (rc.right-rc.left)
79
#define RECTH(rc) (rc.bottom-rc.top)
80
 
81
static DWORD GetWindowStyle (HWND hwnd)
82
{
83
        return hwnd->style;
84
}
85
 
86
static COLORREF GetWindowBkColor (HWND hwnd)
87
{
88
        MWBRUSHOBJ *hbr;
89
        hbr=(MWBRUSHOBJ *)hwnd->pClass->hbrBackground;
90
        return hbr->color;
91
}
92
 
93
static char *GetWindowCaption (HWND hwnd)
94
{
95
        return hwnd->szTitle;
96
}
97
 
98
static void SetWindowCaption (HWND hwnd,char *caption)
99
{
100
        if (strlen(caption)<=63)        /* mw: szTitle[64] */
101
                strcpy(hwnd->szTitle,caption);
102
        else
103
        {
104
                strncpy(hwnd->szTitle,caption,63);
105
                hwnd->szTitle[63]='\0';
106
        }
107
}
108
 
109
static int GetSysCharHeight (HWND hwnd)
110
{
111
        HDC             hdc;
112
        int xw, xh, xb;
113
 
114
        hdc = GetDC(hwnd);
115
 
116
        SelectObject(hdc, GetStockObject(FONT_NAME));
117
 
118
#if MWCLIENT    /* nanox client */
119
        GrGetGCTextSize(hdc->gc, "X", 1, MWTF_ASCII, &xw, &xh, &xb);
120
#else
121
        GdGetTextSize(hdc->font->pfont,"X",1, &xw,&xh,&xb,MWTF_ASCII);
122
#endif
123
        ReleaseDC(hwnd,hdc);
124
 
125
        return xh;
126
}
127
 
128
static int GetSysCharWidth (HWND hwnd)
129
{
130
        HDC             hdc;
131
        int xw, xh, xb;
132
 
133
        hdc = GetDC(hwnd);
134
 
135
        SelectObject(hdc, GetStockObject(FONT_NAME));
136
 
137
#if MWCLIENT    /* nanox client */
138
        GrGetGCTextSize(hdc->gc, "X", 1, MWTF_ASCII, &xw, &xh, &xb);
139
#else
140
        GdGetTextSize(hdc->font->pfont,"X",1, &xw,&xh,&xb,MWTF_ASCII);
141
#endif
142
        ReleaseDC(hwnd,hdc);
143
 
144
        return xw;
145
}
146
#endif
147
 
148
static LRESULT CALLBACK
149
StaticControlProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
150
{
151
    RECT        rcClient;
152
    HDC         hdc;
153
    char*       spCaption;
154
    HWND        pCtrl;
155
    UINT        uFormat;
156
    DWORD       dwStyle;
157
 
158
    pCtrl = hwnd;
159
    switch (message) {
160
        case WM_CREATE:
161
            return 0;
162
 
163
        case WM_DESTROY:
164
            break;
165
 
166
        case STM_GETIMAGE:
167
            return (int)(pCtrl->userdata);
168
 
169
        case STM_SETIMAGE:
170
        {
171
            int pOldValue;
172
 
173
            pOldValue  = (int)(pCtrl->userdata);
174
            pCtrl->userdata = (DWORD)wParam;
175
            InvalidateRect (hwnd, NULL, FALSE);
176
            return pOldValue;
177
        }
178
 
179
        case WM_GETDLGCODE:
180
            return DLGC_STATIC;
181
 
182
 
183
        case WM_PAINT:
184
        {
185
            PAINTSTRUCT ps;
186
            RECT rc;
187
            HBRUSH hbr;
188
 
189
            hdc = BeginPaint (hwnd,&ps);
190
 
191
            GetClientRect (hwnd, &rcClient);
192
 
193
            FastFillRect(hdc, &rcClient, GetSysColor(COLOR_BTNFACE));
194
 
195
            dwStyle = GetWindowStyle (hwnd);
196
 
197
            switch (dwStyle & SS_TYPEMASK)
198
            {
199
                case SS_GRAYRECT:
200
#if 0
201
                    SetBrushColor (hdc, LTGRAY);
202
                    FillBox(hdc, 0, 0, RECTW(rcClient), RECTH(rcClient));
203
#else
204
                    rc.left=0; rc.top=0; rc.bottom=RECTH(rcClient); rc.right=RECTW(rcClient);
205
                    FillRect(hdc,&rc,GetStockObject(LTGRAY_BRUSH));
206
#endif
207
                break;
208
 
209
                case SS_GRAYFRAME:
210
#if 0
211
                    Draw3DDownFrame (hdc,
212
                            0, 0, rcClient.right, rcClient.bottom,
213
                            DKGRAY);
214
#else
215
                    Draw3dInset(hdc, 0, 0,
216
                        rcClient.right, rcClient.bottom);
217
#endif
218
                break;
219
 
220
                case SS_BITMAP:
221
#if 0   /* jmt: fix: no FillBoxWithBitmap() */
222
                    FillBoxWithBitmap(hdc, 0, 0, 0, 0,
223
                        (PBITMAP)(pCtrl->userdata));
224
#endif
225
                break;
226
 
227
                case SS_ICON:
228
#if 0   /* jmt: fix: no DrawIcon */
229
                    hIcon = (HICON)(pCtrl->userdata);
230
                    DrawIcon (hdc, 0, 0, 0, 0, hIcon);
231
#endif
232
                break;
233
 
234
                case SS_SIMPLE:
235
#if 0
236
                    SetBrushColor (hdc, GetWindowBkColor (hwnd));
237
                    FillBox (hdc, 0, 0, rcClient.right, rcClient.bottom);
238
#else
239
                    hbr=CreateSolidBrush(GetWindowBkColor(hwnd));
240
                    rc.left=0; rc.top=0; rc.bottom=rcClient.bottom; rc.right=rcClient.right;
241
                    FillRect(hdc,&rc,hbr);
242
                    DeleteObject(hbr);
243
#endif        
244
                    if (dwStyle & WS_DISABLED)
245
                        SetTextColor (hdc, DKGRAY);
246
                    else
247
                        SetTextColor (hdc, BLACK);
248
                    SetBkColor(hdc, GetSysColor(COLOR_BTNFACE));
249
                    spCaption = GetWindowCaption (hwnd);
250
                    if (spCaption)
251
                    {
252
                        SelectObject(hdc, GetStockObject(FONT_NAME));
253
                        TextOut (hdc, 0, 0, spCaption, -1);
254
                    }
255
                break;
256
 
257
                case SS_LEFT:
258
                case SS_CENTER:
259
                case SS_RIGHT:
260
                case SS_LEFTNOWORDWRAP:
261
                    uFormat = DT_TOP;
262
                    if ( (dwStyle & SS_TYPEMASK) == SS_LEFT)
263
                        uFormat |= DT_LEFT | DT_WORDBREAK;
264
                    else if ( (dwStyle & SS_TYPEMASK) == SS_CENTER)
265
                        uFormat |= DT_CENTER | DT_WORDBREAK;
266
                    else if ( (dwStyle & SS_TYPEMASK) == SS_RIGHT)
267
                        uFormat |= DT_RIGHT | DT_WORDBREAK;
268
                    else if ( (dwStyle & SS_TYPEMASK) == SS_LEFTNOWORDWRAP)
269
                        uFormat |= DT_LEFT | DT_SINGLELINE | DT_EXPANDTABS;
270
 
271
                    if (dwStyle & WS_DISABLED)
272
                        SetTextColor (hdc, DKGRAY);
273
                    else
274
                        SetTextColor (hdc, BLACK);
275
 
276
#if 0
277
                    SetBkColor (hdc, GetWindowBkColor (hwnd));
278
#endif
279
                    SetBkColor(hdc, GetSysColor(COLOR_BTNFACE));
280
                    spCaption = GetWindowCaption (hwnd);
281
                    if (dwStyle & SS_NOPREFIX)
282
                        uFormat |= DT_NOPREFIX;
283
 
284
                    if (spCaption)
285
                    {
286
                        SelectObject(hdc, GetStockObject(FONT_NAME));
287
                        DrawText (hdc, spCaption, -1, &rcClient, uFormat);
288
                    }
289
                break;
290
 
291
                case SS_GROUPBOX:
292
#if 0
293
                    Draw3DBorder (hdc,  rcClient.left,
294
                            rcClient.top + (GetSysCharHeight(hwnd) >> 1),
295
                            rcClient.right, rcClient.bottom);
296
#else
297
                    Draw3dInset(hdc, rcClient.left,
298
                        rcClient.top+(GetSysCharHeight(hwnd) >> 1),
299
                        rcClient.right-rcClient.left,
300
                        rcClient.bottom-rcClient.top);
301
#endif                    
302
                    if (dwStyle & WS_DISABLED)
303
                        SetTextColor (hdc, DKGRAY);
304
                    else
305
                        SetTextColor (hdc, BLACK);
306
 
307
#if 0
308
                    SetBkColor(hdc, GetWindowBkColor (GetParent (hwnd)));
309
#endif
310
                    SetBkColor(hdc, GetSysColor(COLOR_BTNFACE));
311
                    spCaption = GetWindowCaption (hwnd);
312
                    if (spCaption)
313
                    {
314
                        SelectObject(hdc, GetStockObject(FONT_NAME));
315
                        TextOut (hdc, GetSysCharWidth (hwnd), 2, spCaption, -1);
316
                    }
317
                break;
318
            }
319
            EndPaint (hwnd, &ps);
320
        }
321
            break;
322
 
323
#if 0   /* jmt: SS_NOTIFY isn't standard in win32 */
324
        case WM_LBUTTONDBLCLK:
325
            if (GetWindowStyle (hwnd) & SS_NOTIFY)
326
                SendMessage (GetParent(hwnd), WM_COMMAND,
327
                    (WPARAM)MAKELONG(pCtrl->id, STN_DBLCLK),
328
                    (LPARAM)hwnd);
329
            break;
330
#endif
331
        case WM_LBUTTONDOWN:
332
            break;
333
 
334
        case WM_NCLBUTTONDBLCLK:
335
            break;
336
 
337
        case WM_NCLBUTTONDOWN:
338
            break;
339
 
340
        case WM_NCHITTEST:
341
            dwStyle = GetWindowStyle (hwnd);
342
            if ((dwStyle & SS_TYPEMASK) == SS_GROUPBOX)
343
                return HTTRANSPARENT;
344
 
345
#if 0   /* jmt: SS_NOTIFY isn't standard in win32 */
346
            if (GetWindowStyle (hwnd) & SS_NOTIFY)
347
                return HTCLIENT;
348
            else
349
#endif
350
                return HTNOWHERE;
351
        break;
352
 
353
 
354
#if 0   /* jmt: fix: no WM_GETFONT/WM_SETFONT */
355
        case WM_GETFONT:
356
            break;
357
        case WM_SETFONT:
358
            break;
359
#endif
360
        case WM_SETTEXT:
361
            SetWindowCaption (hwnd, (char*)lParam);
362
            InvalidateRect (hwnd, NULL, TRUE);
363
            break;
364
 
365
        default:
366
                return DefWindowProc (hwnd, message, wParam, lParam);
367
    }
368
    return 0;
369
}

powered by: WebSVN 2.1.0

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