File: scrollwin.cc

package info (click to toggle)
bochs 3.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 25,244 kB
  • sloc: cpp: 270,331; ansic: 25,334; sh: 8,371; makefile: 5,512; yacc: 1,485; asm: 395; perl: 359; lex: 318; csh: 3
file content (173 lines) | stat: -rw-r--r-- 4,842 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
/////////////////////////////////////////////////////////////////////////
// $Id$
/////////////////////////////////////////////////////////////////////////
//
//  Copyright (C) 2013-2014  Volker Ruppert
//
//  This library is free software; you can redistribute it and/or
//  modify it under the terms of the GNU Lesser General Public
//  License as published by the Free Software Foundation; either
//  version 2 of the License, or (at your option) any later version.
//
//  This library is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
//  Lesser General Public License for more details.
//
//  You should have received a copy of the GNU Lesser General Public
//  License along with this library; if not, write to the Free Software
//  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA

// Define BX_PLUGGABLE in files that can be compiled into plugins.  For
// platforms that require a special tag on exported symbols, BX_PLUGGABLE
// is used to know when we are exporting symbols and when we are importing.
#define BX_PLUGGABLE

#include "config.h"

#if BX_USE_WIN32CONFIG

#include <windows.h>
#include <commctrl.h>

LRESULT CALLBACK ScrollWinProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
  SCROLLINFO si;
  BOOL pull = FALSE, redraw = FALSE;
  static int vsize = 0, wsize = 0, starty = 0;
  int scrolly, oldy = 0;
  short delta;
  RECT R;

  oldy = starty;
  switch (msg) {
    case WM_CREATE:
      GetClientRect(hwnd, &R);
      wsize = R.bottom;
      vsize = wsize;
      starty = 0;
      si.cbSize = sizeof(SCROLLINFO);
      si.fMask = SIF_POS | SIF_PAGE | SIF_RANGE | SIF_DISABLENOSCROLL;
      si.nMin = 0;
      si.nMax = vsize - 1;
      si.nPage = wsize;
      si.nPos = starty;
      SetScrollInfo(hwnd, SB_VERT, &si, TRUE);
      break;
    case WM_VSCROLL:
      switch (LOWORD(wParam)) {
        case SB_LINEDOWN:
          if (starty < (vsize - wsize)) {
            starty++;
            redraw = TRUE;
          }
          break;
        case SB_LINEUP:
          if (starty > 0) {
            starty--;
            redraw = TRUE;
          }
          break;
        case SB_PAGEDOWN:
          if (starty < (vsize - wsize)) {
            starty += wsize;
            if (starty > (vsize - wsize)) {
              starty = vsize - wsize;
            }
            redraw = TRUE;
          }
          break;
        case SB_PAGEUP:
          if (starty > 0) {
            starty -= wsize;
            if (starty < 0) starty = 0;
            redraw = TRUE;
          }
          break;
        case SB_TOP:
          if (starty > 0) {
            starty = 0;
            redraw = TRUE;
          }
          break;
        case SB_BOTTOM:
          starty = vsize - wsize;
          redraw = TRUE;
          break;
        case SB_THUMBPOSITION:
          redraw = TRUE;
          break;
        case SB_THUMBTRACK:
          starty = HIWORD(wParam);
          SetScrollPos(hwnd, SB_VERT, starty, TRUE);
          pull = TRUE;
          redraw = (starty != oldy);
          break;
      }
      break;
    case WM_MOUSEWHEEL:
      delta = (short)HIWORD(wParam);
      if (delta < 0) {
        if (starty < (vsize - wsize)) {
          starty += 3;
          if (starty > (vsize - wsize)) {
            starty = vsize - wsize;
          }
          redraw = TRUE;
          break;
        }
      } else if (delta > 0) {
        if (starty > 0) {
          starty -= 3;
          if (starty < 0) starty = 0;
          redraw = TRUE;
          break;
        }
      }
      return 0;
    case WM_USER:
      if (wParam == 0x1234) {
        vsize = (int)lParam;
        si.cbSize = sizeof(SCROLLINFO);
        si.fMask = SIF_RANGE | SIF_DISABLENOSCROLL;
        si.nMin = 0;
        si.nMax = vsize - 1;
        SetScrollInfo(hwnd, SB_VERT, &si, TRUE);
        redraw = TRUE;
      }
      break;
  }
  if (redraw) {
    if (!pull) {
      SetScrollPos(hwnd, SB_VERT, starty, TRUE);
    }
    scrolly = oldy - starty;
    if (scrolly != 0) {
      ScrollWindowEx(hwnd, 0, scrolly, NULL, NULL, NULL, NULL, SW_INVALIDATE | SW_ERASE | SW_SCROLLCHILDREN);
    }
    return 0;
  } else {
    return DefWindowProc(hwnd, msg, wParam,lParam);
  }
}

BOOL RegisterScrollWindow(HINSTANCE hinst)
{
  WNDCLASS wc;

  memset(&wc,0,sizeof(WNDCLASS));
  wc.style         = CS_HREDRAW | CS_VREDRAW;
  wc.lpfnWndProc   = (WNDPROC)ScrollWinProc;
  wc.cbClsExtra    = 0;
  wc.cbWndExtra    = 0;
  wc.hInstance     = hinst;
  wc.hIcon         = NULL;
  wc.hCursor       = LoadCursor(NULL, IDC_ARROW);
  wc.hbrBackground = GetSysColorBrush(COLOR_3DFACE);
  wc.lpszMenuName  = NULL;
  wc.lpszClassName = "ScrollWin";

  return (RegisterClass(&wc) != 0);
}

#endif