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

Subversion Repositories or1k_old

[/] [or1k_old/] [trunk/] [mw/] [src/] [mwin/] [winlib/] [caret.c] - Blame information for rev 1782

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 673 markom
/*
2
 * Copyright (c) 2000 Greg Haerr <greg@censoft.com>
3
 *
4
 * Caret control for Microwindows win32 api.
5
 *
6
 * TODO: add SetSysTimer for blinking
7
 */
8
#include <stdio.h>
9
#include <stdlib.h>
10
#include <sys/time.h>
11
#ifndef __ECOS
12
#include <malloc.h>
13
#endif
14
#include "windows.h"
15
#include "device.h"
16
 
17
#define DEF_BLINK_TIME          500     /* default blink time in ms*/
18
 
19
typedef struct {
20
        HWND    hwnd;           /* != NULL if caret is created*/
21
        int     x;
22
        int     y;
23
        int     nWidth;
24
        int     nHeight;
25
        BOOL    fShown;         /* caret is currently visible*/
26
        int     nShowCount;     /* <= 0 for hidden caret*/
27
        UINT    nBlinkTime;
28
} CARETINFO;
29
 
30
/* local data*/
31
static CARETINFO sysCaret;      /* the system caret*/
32
 
33
/* local procs*/
34
static void MwShowCaret(void);
35
static void MwHideCaret(void);
36
static void MwUpdateCaret(void);
37
 
38
BOOL WINAPI
39
CreateCaret(HWND hwnd, HBITMAP hBitmap, int nWidth, int nHeight)
40
{
41
 
42
        DestroyCaret();                 /* destroy old caret if any*/
43
 
44
        if (nWidth <= 0)
45
                nWidth = 1;
46
        if (nHeight <= 0)
47
                nHeight = 1;
48
 
49
        sysCaret.hwnd = hwnd;
50
        sysCaret.x = 0;
51
        sysCaret.y = 0;
52
        sysCaret.nWidth = nWidth;
53
        sysCaret.nHeight = nHeight;
54
        sysCaret.fShown = FALSE;
55
        sysCaret.nShowCount = 0;
56
        sysCaret.nBlinkTime = DEF_BLINK_TIME;
57
        return TRUE;
58
}
59
 
60
BOOL WINAPI
61
DestroyCaret(VOID)
62
{
63
        if (sysCaret.fShown)
64
                MwHideCaret();
65
        sysCaret.hwnd = NULL;
66
        sysCaret.fShown = FALSE;
67
        return TRUE;
68
}
69
 
70
BOOL WINAPI
71
HideCaret(HWND hwnd)
72
{
73
        if (hwnd == NULL)
74
                hwnd = sysCaret.hwnd;
75
        if (hwnd == NULL || hwnd != sysCaret.hwnd)
76
                return FALSE;
77
 
78
        /* hide caret if this call made it invisible*/
79
        if (--sysCaret.nShowCount == 0) {
80
                MwHideCaret();
81
                return TRUE;
82
        }
83
        return FALSE;
84
}
85
 
86
BOOL WINAPI
87
ShowCaret(HWND hwnd)
88
{
89
        if (hwnd == NULL)
90
                hwnd = sysCaret.hwnd;
91
        if (hwnd == NULL || hwnd != sysCaret.hwnd || sysCaret.nShowCount < 0)
92
                return FALSE;
93
 
94
        if (++sysCaret.nShowCount > 1)
95
                return TRUE;
96
 
97
        /* show caret, this call made it visible*/
98
        MwShowCaret();
99
        return TRUE;
100
}
101
 
102
BOOL WINAPI
103
SetCaretPos(int nX, int nY)
104
{
105
        if (sysCaret.fShown && (sysCaret.x != nX || sysCaret.y != nY)) {
106
                MwUpdateCaret();        /* toggle off*/
107
                sysCaret.x = nX;
108
                sysCaret.y = nY;
109
                MwUpdateCaret();        /* toggle on in new location*/
110
                return TRUE;
111
        }
112
        sysCaret.x = nX;
113
        sysCaret.y = nY;
114
        return TRUE;
115
}
116
 
117
BOOL WINAPI
118
GetCaretPos(LPPOINT lpPoint)
119
{
120
        lpPoint->x = sysCaret.x;
121
        lpPoint->y = sysCaret.y;
122
        return TRUE;
123
}
124
 
125
UINT WINAPI
126
GetCaretBlinkTime(VOID)
127
{
128
        return sysCaret.nBlinkTime;
129
}
130
 
131
BOOL WINAPI
132
SetCaretBlinkTime(UINT uMSeconds)
133
{
134
        sysCaret.nBlinkTime = uMSeconds;
135
        /* SetSysTimer */
136
        return TRUE;
137
}
138
 
139
static void
140
MwShowCaret(void)
141
{
142
        if (sysCaret.fShown)
143
                return;
144
        MwUpdateCaret();
145
        sysCaret.fShown = TRUE;
146
}
147
 
148
static void
149
MwHideCaret(void)
150
{
151
        if (!sysCaret.fShown)
152
                return;
153
        MwUpdateCaret();
154
        sysCaret.fShown = FALSE;
155
}
156
 
157
/* Draw the caret using XOR.  Same routine is used to show and hide caret.*/
158
static void
159
MwUpdateCaret(void)
160
{
161
        int     oldmode;
162
        HDC     hdc;
163
        HPEN    hpen;
164
        HBRUSH  hbr;
165
 
166
        oldmode = GdSetMode(MWMODE_XOR);
167
        hdc = GetDC(sysCaret.hwnd);
168
        hpen = SelectObject(hdc, GetStockObject(WHITE_PEN));
169
 
170
        /* it seems there's some problems with Rectangle with nWidth == 1*/
171
        if (sysCaret.nWidth == 1) {
172
                MoveToEx(hdc, sysCaret.x, sysCaret.y, NULL);
173
                LineTo(hdc, sysCaret.x, sysCaret.y+sysCaret.nHeight);
174
        } else {
175
                hbr = SelectObject(hdc, GetStockObject(WHITE_BRUSH));
176
                Rectangle(hdc, sysCaret.x, sysCaret.y,
177
                        sysCaret.x+sysCaret.nWidth,
178
                        sysCaret.y+sysCaret.nHeight);
179
                SelectObject(hdc, hbr);
180
        }
181
        SelectObject(hdc, hpen);
182
        ReleaseDC(sysCaret.hwnd, hdc);
183
        GdSetMode(oldmode);
184
}

powered by: WebSVN 2.1.0

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