]>
Commit | Line | Data |
---|---|---|
1e6feb95 | 1 | /////////////////////////////////////////////////////////////////////////////// |
e4db172a | 2 | // Name: src/univ/window.cpp |
1e6feb95 VZ |
3 | // Purpose: implementation of extra wxWindow methods for wxUniv port |
4 | // Author: Vadim Zeitlin | |
5 | // Modified by: | |
6 | // Created: 06.08.00 | |
7 | // RCS-ID: $Id$ | |
442b35b5 | 8 | // Copyright: (c) 2000 SciTech Software, Inc. (www.scitechsoft.com) |
65571936 | 9 | // Licence: wxWindows licence |
1e6feb95 VZ |
10 | /////////////////////////////////////////////////////////////////////////////// |
11 | ||
12 | // =========================================================================== | |
13 | // declarations | |
14 | // =========================================================================== | |
15 | ||
16 | // --------------------------------------------------------------------------- | |
17 | // headers | |
18 | // --------------------------------------------------------------------------- | |
19 | ||
1e6feb95 VZ |
20 | // For compilers that support precompilation, includes "wx.h". |
21 | #include "wx/wxprec.h" | |
22 | ||
23 | #ifdef __BORLANDC__ | |
24 | #pragma hdrstop | |
25 | #endif | |
26 | ||
e4db172a WS |
27 | #include "wx/window.h" |
28 | ||
1e6feb95 VZ |
29 | #ifndef WX_PRECOMP |
30 | #include "wx/app.h" | |
1e6feb95 VZ |
31 | #include "wx/dcclient.h" |
32 | #include "wx/dcmemory.h" | |
33 | #include "wx/event.h" | |
34 | #include "wx/scrolbar.h" | |
35 | #include "wx/menu.h" | |
8cb172b4 | 36 | #include "wx/frame.h" |
e4db172a | 37 | #include "wx/log.h" |
1e6feb95 VZ |
38 | #endif // WX_PRECOMP |
39 | ||
40 | #include "wx/univ/colschem.h" | |
41 | #include "wx/univ/renderer.h" | |
42 | #include "wx/univ/theme.h" | |
43 | ||
44 | #if wxUSE_CARET | |
45 | #include "wx/caret.h" | |
46 | #endif // wxUSE_CARET | |
47 | ||
48 | // turn Refresh() debugging on/off | |
49 | #define WXDEBUG_REFRESH | |
50 | ||
51 | #ifndef __WXDEBUG__ | |
52 | #undef WXDEBUG_REFRESH | |
53 | #endif | |
54 | ||
cff7ef89 VS |
55 | #if defined(WXDEBUG_REFRESH) && defined(__WXMSW__) && !defined(__WXMICROWIN__) |
56 | #include "wx/msw/private.h" | |
57 | #endif | |
58 | ||
1e6feb95 VZ |
59 | // ============================================================================ |
60 | // implementation | |
61 | // ============================================================================ | |
62 | ||
63 | // ---------------------------------------------------------------------------- | |
64 | // event tables | |
65 | // ---------------------------------------------------------------------------- | |
66 | ||
67 | // we can't use wxWindowNative here as it won't be expanded inside the macro | |
68 | #if defined(__WXMSW__) | |
69 | IMPLEMENT_DYNAMIC_CLASS(wxWindow, wxWindowMSW) | |
70 | #elif defined(__WXGTK__) | |
71 | IMPLEMENT_DYNAMIC_CLASS(wxWindow, wxWindowGTK) | |
72 | #elif defined(__WXMGL__) | |
73 | IMPLEMENT_DYNAMIC_CLASS(wxWindow, wxWindowMGL) | |
8354aa92 RR |
74 | #elif defined(__WXX11__) |
75 | IMPLEMENT_DYNAMIC_CLASS(wxWindow, wxWindowX11) | |
19193a2c KB |
76 | #elif defined(__WXPM__) |
77 | IMPLEMENT_DYNAMIC_CLASS(wxWindow, wxWindowOS2) | |
1e6feb95 VZ |
78 | #endif |
79 | ||
80 | BEGIN_EVENT_TABLE(wxWindow, wxWindowNative) | |
81 | EVT_SIZE(wxWindow::OnSize) | |
82 | ||
83 | #if wxUSE_ACCEL || wxUSE_MENUS | |
84 | EVT_KEY_DOWN(wxWindow::OnKeyDown) | |
85 | #endif // wxUSE_ACCEL | |
86 | ||
87 | #if wxUSE_MENUS | |
88 | EVT_CHAR(wxWindow::OnChar) | |
89 | EVT_KEY_UP(wxWindow::OnKeyUp) | |
90 | #endif // wxUSE_MENUS | |
91 | ||
92 | EVT_PAINT(wxWindow::OnPaint) | |
93 | EVT_NC_PAINT(wxWindow::OnNcPaint) | |
94 | EVT_ERASE_BACKGROUND(wxWindow::OnErase) | |
95 | END_EVENT_TABLE() | |
96 | ||
97 | // ---------------------------------------------------------------------------- | |
98 | // creation | |
99 | // ---------------------------------------------------------------------------- | |
100 | ||
101 | void wxWindow::Init() | |
102 | { | |
103 | m_scrollbarVert = | |
104 | m_scrollbarHorz = (wxScrollBar *)NULL; | |
105 | ||
a290fa5a | 106 | m_isCurrent = false; |
1e6feb95 VZ |
107 | |
108 | m_renderer = wxTheme::Get()->GetRenderer(); | |
2b5f62a0 | 109 | |
a290fa5a WS |
110 | m_oldSize.x = wxDefaultCoord; |
111 | m_oldSize.y = wxDefaultCoord; | |
1e6feb95 VZ |
112 | } |
113 | ||
114 | bool wxWindow::Create(wxWindow *parent, | |
115 | wxWindowID id, | |
116 | const wxPoint& pos, | |
117 | const wxSize& size, | |
118 | long style, | |
119 | const wxString& name) | |
120 | { | |
588cf92f | 121 | long actualStyle = style; |
8da1f9a9 | 122 | |
588cf92f JS |
123 | // FIXME: may need this on other platforms |
124 | #ifdef __WXMSW__ | |
125 | actualStyle &= ~wxVSCROLL; | |
126 | actualStyle &= ~wxHSCROLL; | |
8da1f9a9 VZ |
127 | #endif |
128 | ||
2387541f VZ |
129 | // we add wxCLIP_CHILDREN to get the same ("natural") behaviour under MSW |
130 | // as under the other platforms | |
1e6feb95 | 131 | if ( !wxWindowNative::Create(parent, id, pos, size, |
588cf92f | 132 | actualStyle | wxCLIP_CHILDREN, |
2387541f | 133 | name) ) |
1e6feb95 | 134 | { |
a290fa5a | 135 | return false; |
1e6feb95 VZ |
136 | } |
137 | ||
588cf92f JS |
138 | // Set full style again, including those we didn't want present |
139 | // when calling the base window Create(). | |
140 | wxWindowBase::SetWindowStyleFlag(style); | |
141 | ||
1cb853a8 JS |
142 | // if we allow or should always have a vertical scrollbar, make it |
143 | if ( style & wxVSCROLL || style & wxALWAYS_SHOW_SB ) | |
1e6feb95 | 144 | { |
ab6b6b15 | 145 | #if wxUSE_TWO_WINDOWS |
a290fa5a | 146 | SetInsertIntoMain( true ); |
ab6b6b15 | 147 | #endif |
a290fa5a | 148 | m_scrollbarVert = new wxScrollBar(this, wxID_ANY, |
1e6feb95 VZ |
149 | wxDefaultPosition, wxDefaultSize, |
150 | wxSB_VERTICAL); | |
ab6b6b15 | 151 | #if wxUSE_TWO_WINDOWS |
a290fa5a | 152 | SetInsertIntoMain( false ); |
ab6b6b15 | 153 | #endif |
588cf92f | 154 | } |
1e6feb95 | 155 | |
1cb853a8 | 156 | // if we should allow a horizontal scrollbar, make it |
588cf92f JS |
157 | if ( style & wxHSCROLL ) |
158 | { | |
159 | #if wxUSE_TWO_WINDOWS | |
a290fa5a | 160 | SetInsertIntoMain( true ); |
588cf92f | 161 | #endif |
a290fa5a | 162 | m_scrollbarHorz = new wxScrollBar(this, wxID_ANY, |
588cf92f JS |
163 | wxDefaultPosition, wxDefaultSize, |
164 | wxSB_HORIZONTAL); | |
165 | #if wxUSE_TWO_WINDOWS | |
a290fa5a | 166 | SetInsertIntoMain( false ); |
588cf92f JS |
167 | #endif |
168 | } | |
8da1f9a9 | 169 | |
588cf92f JS |
170 | if (m_scrollbarHorz || m_scrollbarVert) |
171 | { | |
172 | // position it/them | |
1e6feb95 VZ |
173 | PositionScrollbars(); |
174 | } | |
175 | ||
a290fa5a | 176 | return true; |
1e6feb95 VZ |
177 | } |
178 | ||
8da1f9a9 VZ |
179 | wxWindow::~wxWindow() |
180 | { | |
181 | m_isBeingDeleted = true; | |
182 | ||
183 | // we have to destroy our children before we're destroyed because our | |
184 | // children suppose that we're of type wxWindow, not just wxWindowNative, | |
185 | // and so bad things may happen if they're deleted from the base class dtor | |
186 | // as by then we're not a wxWindow any longer and wxUniv-specific virtual | |
187 | // functions can't be called | |
188 | DestroyChildren(); | |
189 | } | |
190 | ||
1e6feb95 VZ |
191 | // ---------------------------------------------------------------------------- |
192 | // background pixmap | |
193 | // ---------------------------------------------------------------------------- | |
194 | ||
195 | void wxWindow::SetBackground(const wxBitmap& bitmap, | |
196 | int alignment, | |
197 | wxStretch stretch) | |
198 | { | |
199 | m_bitmapBg = bitmap; | |
200 | m_alignBgBitmap = alignment; | |
201 | m_stretchBgBitmap = stretch; | |
202 | } | |
203 | ||
204 | const wxBitmap& wxWindow::GetBackgroundBitmap(int *alignment, | |
205 | wxStretch *stretch) const | |
206 | { | |
207 | if ( m_bitmapBg.Ok() ) | |
208 | { | |
209 | if ( alignment ) | |
210 | *alignment = m_alignBgBitmap; | |
211 | if ( stretch ) | |
212 | *stretch = m_stretchBgBitmap; | |
213 | } | |
214 | ||
215 | return m_bitmapBg; | |
216 | } | |
217 | ||
218 | // ---------------------------------------------------------------------------- | |
219 | // painting | |
220 | // ---------------------------------------------------------------------------- | |
221 | ||
1e6feb95 | 222 | // the event handlers executed when the window must be repainted |
3795cdba | 223 | void wxWindow::OnNcPaint(wxNcPaintEvent& WXUNUSED(event)) |
1e6feb95 VZ |
224 | { |
225 | if ( m_renderer ) | |
226 | { | |
227 | // get the window rect | |
228 | wxRect rect; | |
229 | wxSize size = GetSize(); | |
230 | rect.x = | |
231 | rect.y = 0; | |
232 | rect.width = size.x; | |
233 | rect.height = size.y; | |
234 | ||
235 | // if the scrollbars are outside the border, we must adjust the rect to | |
236 | // exclude them | |
237 | if ( !m_renderer->AreScrollbarsInsideBorder() ) | |
238 | { | |
239 | wxScrollBar *scrollbar = GetScrollbar(wxVERTICAL); | |
240 | if ( scrollbar ) | |
241 | rect.width -= scrollbar->GetSize().x; | |
242 | ||
243 | scrollbar = GetScrollbar(wxHORIZONTAL); | |
244 | if ( scrollbar ) | |
245 | rect.height -= scrollbar->GetSize().y; | |
246 | } | |
247 | ||
248 | // get the DC and draw the border on it | |
249 | wxWindowDC dc(this); | |
250 | DoDrawBorder(dc, rect); | |
251 | } | |
252 | } | |
253 | ||
254 | void wxWindow::OnPaint(wxPaintEvent& event) | |
255 | { | |
256 | if ( !m_renderer ) | |
257 | { | |
258 | // it is a native control which paints itself | |
259 | event.Skip(); | |
260 | } | |
261 | else | |
262 | { | |
263 | // get the DC to use and create renderer on it | |
264 | wxPaintDC dc(this); | |
265 | wxControlRenderer renderer(this, dc, m_renderer); | |
266 | ||
267 | // draw the control | |
268 | DoDraw(&renderer); | |
269 | } | |
270 | } | |
271 | ||
5ebcf581 RR |
272 | // the event handler executed when the window background must be painted |
273 | void wxWindow::OnErase(wxEraseEvent& event) | |
274 | { | |
275 | if ( !m_renderer ) | |
276 | { | |
277 | event.Skip(); | |
278 | ||
279 | return; | |
280 | } | |
2b5f62a0 | 281 | |
5ebcf581 RR |
282 | DoDrawBackground(*event.GetDC()); |
283 | ||
284 | // if we have both scrollbars, we also have a square in the corner between | |
285 | // them which we must paint | |
286 | if ( m_scrollbarVert && m_scrollbarHorz ) | |
287 | { | |
288 | wxSize size = GetSize(); | |
289 | wxRect rectClient = GetClientRect(), | |
290 | rectBorder = m_renderer->GetBorderDimensions(GetBorder()); | |
291 | ||
292 | wxRect rectCorner; | |
293 | rectCorner.x = rectClient.GetRight() + 1; | |
294 | rectCorner.y = rectClient.GetBottom() + 1; | |
295 | rectCorner.SetRight(size.x - rectBorder.width); | |
296 | rectCorner.SetBottom(size.y - rectBorder.height); | |
297 | ||
298 | if ( GetUpdateRegion().Contains(rectCorner) ) | |
299 | { | |
300 | m_renderer->DrawScrollCorner(*event.GetDC(), rectCorner); | |
301 | } | |
302 | } | |
303 | } | |
304 | ||
1e6feb95 VZ |
305 | bool wxWindow::DoDrawBackground(wxDC& dc) |
306 | { | |
1e6feb95 | 307 | wxRect rect; |
2b5f62a0 | 308 | |
5ebcf581 RR |
309 | wxSize size = GetSize(); // Why not GetClientSize() ? |
310 | rect.x = 0; | |
311 | rect.y = 0; | |
312 | rect.width = size.x; | |
313 | rect.height = size.y; | |
2b5f62a0 VZ |
314 | |
315 | wxWindow * const parent = GetParent(); | |
3d74a760 | 316 | if ( HasTransparentBackground() && parent ) |
1e6feb95 | 317 | { |
5ebcf581 | 318 | wxASSERT( !IsTopLevel() ); |
2b5f62a0 | 319 | |
5ebcf581 | 320 | wxPoint pos = GetPosition(); |
2b5f62a0 | 321 | |
5ebcf581 | 322 | AdjustForParentClientOrigin( pos.x, pos.y, 0 ); |
2b5f62a0 | 323 | |
5ebcf581 | 324 | // Adjust DC logical origin |
635eb8bc JS |
325 | wxCoord org_x, org_y, x, y; |
326 | dc.GetLogicalOrigin( &org_x, &org_y ); | |
327 | x = org_x + pos.x; | |
328 | y = org_y + pos.y; | |
5ebcf581 | 329 | dc.SetLogicalOrigin( x, y ); |
2b5f62a0 | 330 | |
5ebcf581 RR |
331 | // Adjust draw rect |
332 | rect.x = pos.x; | |
333 | rect.y = pos.y; | |
2b5f62a0 | 334 | |
5ebcf581 | 335 | // Let parent draw the background |
2b5f62a0 | 336 | parent->EraseBackground( dc, rect ); |
635eb8bc JS |
337 | |
338 | // Restore DC logical origin | |
339 | dc.SetLogicalOrigin( org_x, org_y ); | |
1e6feb95 | 340 | } |
5ebcf581 RR |
341 | else |
342 | { | |
90e572f1 | 343 | // Draw background ourselves |
2b5f62a0 | 344 | EraseBackground( dc, rect ); |
5ebcf581 | 345 | } |
2b5f62a0 | 346 | |
a290fa5a | 347 | return true; |
5ebcf581 | 348 | } |
1e6feb95 | 349 | |
5ebcf581 RR |
350 | void wxWindow::EraseBackground(wxDC& dc, const wxRect& rect) |
351 | { | |
1e6feb95 VZ |
352 | if ( GetBackgroundBitmap().Ok() ) |
353 | { | |
5ebcf581 | 354 | // Get the bitmap and the flags |
1e6feb95 VZ |
355 | int alignment; |
356 | wxStretch stretch; | |
357 | wxBitmap bmp = GetBackgroundBitmap(&alignment, &stretch); | |
358 | wxControlRenderer::DrawBitmap(dc, bmp, rect, alignment, stretch); | |
359 | } | |
2b5f62a0 | 360 | else |
1e6feb95 | 361 | { |
5ebcf581 | 362 | // Just fill it with bg colour if no bitmap |
2b5f62a0 | 363 | |
1e6feb95 VZ |
364 | m_renderer->DrawBackground(dc, wxTHEME_BG_COLOUR(this), |
365 | rect, GetStateFlags()); | |
366 | } | |
1e6feb95 VZ |
367 | } |
368 | ||
369 | void wxWindow::DoDrawBorder(wxDC& dc, const wxRect& rect) | |
370 | { | |
371 | // draw outline unless the update region is enitrely inside it in which | |
372 | // case we don't need to do it | |
373 | #if 0 // doesn't seem to work, why? | |
374 | if ( wxRegion(rect).Contains(GetUpdateRegion().GetBox()) != wxInRegion ) | |
375 | #endif | |
376 | { | |
377 | m_renderer->DrawBorder(dc, GetBorder(), rect, GetStateFlags()); | |
378 | } | |
379 | } | |
380 | ||
61fef19b | 381 | void wxWindow::DoDraw(wxControlRenderer * WXUNUSED(renderer)) |
1e6feb95 VZ |
382 | { |
383 | } | |
384 | ||
385 | void wxWindow::Refresh(bool eraseBackground, const wxRect *rectClient) | |
386 | { | |
387 | wxRect rectWin; | |
388 | wxPoint pt = GetClientAreaOrigin(); | |
389 | ||
390 | wxSize size = GetClientSize(); | |
391 | ||
392 | if ( rectClient ) | |
393 | { | |
394 | rectWin = *rectClient; | |
395 | ||
396 | // don't refresh anything beyond the client area (scrollbars for | |
397 | // example) | |
398 | if ( rectWin.GetRight() > size.x ) | |
399 | rectWin.SetRight(size.x); | |
400 | if ( rectWin.GetBottom() > size.y ) | |
401 | rectWin.SetBottom(size.y); | |
402 | ||
403 | rectWin.Offset(pt); | |
404 | } | |
405 | else // refresh the entire client area | |
406 | { | |
407 | rectWin.x = pt.x; | |
408 | rectWin.y = pt.y; | |
409 | rectWin.width = size.x; | |
410 | rectWin.height = size.y; | |
411 | } | |
412 | ||
413 | // debugging helper | |
414 | #ifdef WXDEBUG_REFRESH | |
a290fa5a | 415 | static bool s_refreshDebug = false; |
1e6feb95 VZ |
416 | if ( s_refreshDebug ) |
417 | { | |
418 | wxWindowDC dc(this); | |
419 | dc.SetBrush(*wxCYAN_BRUSH); | |
420 | dc.SetPen(*wxTRANSPARENT_PEN); | |
421 | dc.DrawRectangle(rectWin); | |
422 | ||
423 | // under Unix we use "--sync" X option for this | |
8cb172b4 | 424 | #if defined(__WXMSW__) && !defined(__WXMICROWIN__) |
1e6feb95 VZ |
425 | ::GdiFlush(); |
426 | ::Sleep(200); | |
427 | #endif // __WXMSW__ | |
428 | } | |
429 | #endif // WXDEBUG_REFRESH | |
430 | ||
431 | wxWindowNative::Refresh(eraseBackground, &rectWin); | |
82e5f91b JS |
432 | |
433 | // Refresh all sub controls if any. | |
ac32ba44 | 434 | wxWindowList::compatibility_iterator node = GetChildren().GetFirst(); |
82e5f91b JS |
435 | while ( node ) |
436 | { | |
437 | wxWindow *win = node->GetData(); | |
8da1f9a9 | 438 | // Only refresh sub controls when it is visible |
82e5f91b | 439 | // and when it is in the update region. |
333a6456 | 440 | if(!win->IsKindOf(CLASSINFO(wxTopLevelWindow)) && win->IsShown() && wxRegion(rectWin).Contains(win->GetRect()) != wxOutRegion) |
82e5f91b | 441 | win->Refresh(eraseBackground, &rectWin); |
8da1f9a9 | 442 | |
82e5f91b JS |
443 | node = node->GetNext(); |
444 | } | |
1e6feb95 VZ |
445 | } |
446 | ||
447 | // ---------------------------------------------------------------------------- | |
448 | // state flags | |
449 | // ---------------------------------------------------------------------------- | |
450 | ||
451 | bool wxWindow::Enable(bool enable) | |
452 | { | |
453 | if ( !wxWindowNative::Enable(enable) ) | |
a290fa5a | 454 | return false; |
1e6feb95 VZ |
455 | |
456 | // disabled window can't keep focus | |
c4bcd8fc | 457 | if ( FindFocus() == this && GetParent() != NULL ) |
1e6feb95 VZ |
458 | { |
459 | GetParent()->SetFocus(); | |
460 | } | |
461 | ||
462 | if ( m_renderer ) | |
463 | { | |
464 | // a window with renderer is drawn by ourselves and it has to be | |
465 | // refreshed to reflect its new status | |
466 | Refresh(); | |
467 | } | |
468 | ||
a290fa5a | 469 | return true; |
1e6feb95 VZ |
470 | } |
471 | ||
472 | bool wxWindow::IsFocused() const | |
473 | { | |
474 | wxWindow *self = wxConstCast(this, wxWindow); | |
475 | return self->FindFocus() == self; | |
476 | } | |
477 | ||
478 | bool wxWindow::IsPressed() const | |
479 | { | |
a290fa5a | 480 | return false; |
1e6feb95 VZ |
481 | } |
482 | ||
483 | bool wxWindow::IsDefault() const | |
484 | { | |
a290fa5a | 485 | return false; |
1e6feb95 VZ |
486 | } |
487 | ||
488 | bool wxWindow::IsCurrent() const | |
489 | { | |
490 | return m_isCurrent; | |
491 | } | |
492 | ||
493 | bool wxWindow::SetCurrent(bool doit) | |
494 | { | |
495 | if ( doit == m_isCurrent ) | |
a290fa5a | 496 | return false; |
1e6feb95 VZ |
497 | |
498 | m_isCurrent = doit; | |
499 | ||
500 | if ( CanBeHighlighted() ) | |
501 | Refresh(); | |
502 | ||
a290fa5a | 503 | return true; |
1e6feb95 VZ |
504 | } |
505 | ||
506 | int wxWindow::GetStateFlags() const | |
507 | { | |
508 | int flags = 0; | |
509 | if ( !IsEnabled() ) | |
510 | flags |= wxCONTROL_DISABLED; | |
511 | ||
512 | // the following states are only possible if our application is active - if | |
513 | // it is not, even our default/focused controls shouldn't appear as such | |
514 | if ( wxTheApp->IsActive() ) | |
515 | { | |
516 | if ( IsCurrent() ) | |
517 | flags |= wxCONTROL_CURRENT; | |
518 | if ( IsFocused() ) | |
519 | flags |= wxCONTROL_FOCUSED; | |
520 | if ( IsPressed() ) | |
521 | flags |= wxCONTROL_PRESSED; | |
522 | if ( IsDefault() ) | |
523 | flags |= wxCONTROL_ISDEFAULT; | |
524 | } | |
525 | ||
526 | return flags; | |
527 | } | |
528 | ||
529 | // ---------------------------------------------------------------------------- | |
530 | // size | |
531 | // ---------------------------------------------------------------------------- | |
532 | ||
533 | void wxWindow::OnSize(wxSizeEvent& event) | |
534 | { | |
aae73669 | 535 | event.Skip(); |
2b5f62a0 | 536 | |
1e6feb95 VZ |
537 | if ( m_scrollbarVert || m_scrollbarHorz ) |
538 | { | |
539 | PositionScrollbars(); | |
540 | } | |
2b5f62a0 | 541 | |
ab6b6b15 | 542 | #if 0 // ndef __WXMSW__ |
ec47a147 | 543 | // Refresh the area (strip) previously occupied by the border |
2b5f62a0 | 544 | |
e441e1f4 | 545 | if ( !HasFlag(wxFULL_REPAINT_ON_RESIZE) && IsShown() ) |
ec47a147 | 546 | { |
aae73669 RR |
547 | // This code assumes that wxSizeEvent.GetSize() returns |
548 | // the area of the entire window, not just the client | |
549 | // area. | |
ec47a147 | 550 | wxSize newSize = event.GetSize(); |
2b5f62a0 | 551 | |
a290fa5a | 552 | if (m_oldSize.x == wxDefaultCoord && m_oldSize.y == wxDefaultCoord) |
aae73669 RR |
553 | { |
554 | m_oldSize = newSize; | |
555 | return; | |
556 | } | |
2b5f62a0 | 557 | |
ec47a147 RR |
558 | if (HasFlag( wxSIMPLE_BORDER )) |
559 | { | |
560 | if (newSize.y > m_oldSize.y) | |
561 | { | |
562 | wxRect rect; | |
563 | rect.x = 0; | |
564 | rect.width = m_oldSize.x; | |
aae73669 | 565 | rect.y = m_oldSize.y-2; |
ec47a147 | 566 | rect.height = 1; |
a290fa5a | 567 | Refresh( true, &rect ); |
ec47a147 | 568 | } |
aae73669 RR |
569 | else if (newSize.y < m_oldSize.y) |
570 | { | |
571 | wxRect rect; | |
572 | rect.y = newSize.y; | |
573 | rect.x = 0; | |
574 | rect.height = 1; | |
575 | rect.width = newSize.x; | |
a290fa5a | 576 | wxWindowNative::Refresh( true, &rect ); |
aae73669 | 577 | } |
2b5f62a0 | 578 | |
ec47a147 RR |
579 | if (newSize.x > m_oldSize.x) |
580 | { | |
581 | wxRect rect; | |
582 | rect.y = 0; | |
583 | rect.height = m_oldSize.y; | |
aae73669 | 584 | rect.x = m_oldSize.x-2; |
ec47a147 | 585 | rect.width = 1; |
a290fa5a | 586 | Refresh( true, &rect ); |
ec47a147 | 587 | } |
aae73669 RR |
588 | else if (newSize.x < m_oldSize.x) |
589 | { | |
590 | wxRect rect; | |
591 | rect.x = newSize.x; | |
592 | rect.y = 0; | |
593 | rect.width = 1; | |
594 | rect.height = newSize.y; | |
a290fa5a | 595 | wxWindowNative::Refresh( true, &rect ); |
aae73669 | 596 | } |
ec47a147 RR |
597 | } |
598 | else | |
599 | if (HasFlag( wxSUNKEN_BORDER ) || HasFlag( wxRAISED_BORDER )) | |
600 | { | |
601 | if (newSize.y > m_oldSize.y) | |
602 | { | |
603 | wxRect rect; | |
604 | rect.x = 0; | |
605 | rect.width = m_oldSize.x; | |
aae73669 | 606 | rect.y = m_oldSize.y-4; |
ec47a147 | 607 | rect.height = 2; |
a290fa5a | 608 | Refresh( true, &rect ); |
ec47a147 | 609 | } |
aae73669 RR |
610 | else if (newSize.y < m_oldSize.y) |
611 | { | |
612 | wxRect rect; | |
613 | rect.y = newSize.y; | |
614 | rect.x = 0; | |
615 | rect.height = 2; | |
616 | rect.width = newSize.x; | |
a290fa5a | 617 | wxWindowNative::Refresh( true, &rect ); |
aae73669 | 618 | } |
2b5f62a0 | 619 | |
ec47a147 RR |
620 | if (newSize.x > m_oldSize.x) |
621 | { | |
622 | wxRect rect; | |
623 | rect.y = 0; | |
624 | rect.height = m_oldSize.y; | |
aae73669 | 625 | rect.x = m_oldSize.x-4; |
ec47a147 | 626 | rect.width = 2; |
a290fa5a | 627 | Refresh( true, &rect ); |
ec47a147 | 628 | } |
aae73669 RR |
629 | else if (newSize.x < m_oldSize.x) |
630 | { | |
631 | wxRect rect; | |
632 | rect.x = newSize.x; | |
633 | rect.y = 0; | |
634 | rect.width = 2; | |
635 | rect.height = newSize.y; | |
a290fa5a | 636 | wxWindowNative::Refresh( true, &rect ); |
aae73669 | 637 | } |
ec47a147 | 638 | } |
2b5f62a0 | 639 | |
ec47a147 RR |
640 | m_oldSize = newSize; |
641 | } | |
642 | #endif | |
1e6feb95 VZ |
643 | } |
644 | ||
645 | wxSize wxWindow::DoGetBestSize() const | |
646 | { | |
647 | return AdjustSize(DoGetBestClientSize()); | |
648 | } | |
649 | ||
650 | wxSize wxWindow::DoGetBestClientSize() const | |
651 | { | |
652 | return wxWindowNative::DoGetBestSize(); | |
653 | } | |
654 | ||
655 | wxSize wxWindow::AdjustSize(const wxSize& size) const | |
656 | { | |
657 | wxSize sz = size; | |
658 | if ( m_renderer ) | |
659 | m_renderer->AdjustSize(&sz, this); | |
660 | return sz; | |
661 | } | |
662 | ||
663 | wxPoint wxWindow::GetClientAreaOrigin() const | |
664 | { | |
665 | wxPoint pt = wxWindowBase::GetClientAreaOrigin(); | |
666 | ||
ab6b6b15 RR |
667 | #if wxUSE_TWO_WINDOWS |
668 | #else | |
1e6feb95 VZ |
669 | if ( m_renderer ) |
670 | pt += m_renderer->GetBorderDimensions(GetBorder()).GetPosition(); | |
ab6b6b15 | 671 | #endif |
1e6feb95 VZ |
672 | |
673 | return pt; | |
674 | } | |
675 | ||
676 | void wxWindow::DoGetClientSize(int *width, int *height) const | |
677 | { | |
3379ed37 VZ |
678 | // if it is a native window, we assume it handles the scrollbars itself |
679 | // too - and if it doesn't, there is not much we can do | |
680 | if ( !m_renderer ) | |
681 | { | |
682 | wxWindowNative::DoGetClientSize(width, height); | |
683 | ||
684 | return; | |
685 | } | |
686 | ||
1e6feb95 VZ |
687 | int w, h; |
688 | wxWindowNative::DoGetClientSize(&w, &h); | |
689 | ||
690 | // we assume that the scrollbars are positioned correctly (by a previous | |
691 | // call to PositionScrollbars()) here | |
692 | ||
693 | wxRect rectBorder; | |
694 | if ( m_renderer ) | |
695 | rectBorder = m_renderer->GetBorderDimensions(GetBorder()); | |
696 | ||
697 | bool inside = m_renderer->AreScrollbarsInsideBorder(); | |
698 | ||
699 | if ( width ) | |
700 | { | |
701 | // in any case, take account of the scrollbar | |
702 | if ( m_scrollbarVert ) | |
703 | w -= m_scrollbarVert->GetSize().x; | |
704 | ||
705 | // if we don't have scrollbar or if it is outside the border (and not | |
706 | // blended into it), take account of the right border as well | |
707 | if ( !m_scrollbarVert || inside ) | |
708 | w -= rectBorder.width; | |
709 | ||
710 | // and always account for the left border | |
711 | *width = w - rectBorder.x; | |
712 | ||
713 | // we shouldn't return invalid width | |
714 | if ( *width < 0 ) | |
715 | *width = 0; | |
716 | } | |
717 | ||
718 | if ( height ) | |
719 | { | |
720 | if ( m_scrollbarHorz ) | |
721 | h -= m_scrollbarHorz->GetSize().y; | |
722 | ||
723 | if ( !m_scrollbarHorz || inside ) | |
724 | h -= rectBorder.height; | |
725 | ||
726 | *height = h - rectBorder.y; | |
727 | ||
728 | // we shouldn't return invalid height | |
729 | if ( *height < 0 ) | |
730 | *height = 0; | |
731 | } | |
732 | } | |
733 | ||
734 | void wxWindow::DoSetClientSize(int width, int height) | |
735 | { | |
736 | // take into account the borders | |
737 | wxRect rectBorder = m_renderer->GetBorderDimensions(GetBorder()); | |
738 | width += rectBorder.x; | |
739 | height += rectBorder.y; | |
740 | ||
741 | // and the scrollbars (as they may be offset into the border, use the | |
742 | // scrollbar position, not size - this supposes that PositionScrollbars() | |
743 | // had been called before) | |
744 | bool inside = m_renderer->AreScrollbarsInsideBorder(); | |
745 | wxSize size = GetSize(); | |
746 | if ( m_scrollbarVert ) | |
747 | width += size.x - m_scrollbarVert->GetPosition().x; | |
748 | if ( !m_scrollbarVert || inside ) | |
749 | width += rectBorder.width; | |
750 | ||
751 | if ( m_scrollbarHorz ) | |
752 | height += size.y - m_scrollbarHorz->GetPosition().y; | |
753 | if ( !m_scrollbarHorz || inside ) | |
754 | height += rectBorder.height; | |
755 | ||
756 | wxWindowNative::DoSetClientSize(width, height); | |
757 | } | |
758 | ||
759 | wxHitTest wxWindow::DoHitTest(wxCoord x, wxCoord y) const | |
760 | { | |
761 | wxHitTest ht = wxWindowNative::DoHitTest(x, y); | |
762 | if ( ht == wxHT_WINDOW_INSIDE ) | |
763 | { | |
764 | if ( m_scrollbarVert && x >= m_scrollbarVert->GetPosition().x ) | |
765 | { | |
766 | // it can still be changed below because it may also be the corner | |
767 | ht = wxHT_WINDOW_VERT_SCROLLBAR; | |
768 | } | |
769 | ||
770 | if ( m_scrollbarHorz && y >= m_scrollbarHorz->GetPosition().y ) | |
771 | { | |
772 | ht = ht == wxHT_WINDOW_VERT_SCROLLBAR ? wxHT_WINDOW_CORNER | |
773 | : wxHT_WINDOW_HORZ_SCROLLBAR; | |
774 | } | |
775 | } | |
776 | ||
777 | return ht; | |
778 | } | |
779 | ||
780 | // ---------------------------------------------------------------------------- | |
781 | // scrolling: we implement it entirely ourselves except for ScrollWindow() | |
782 | // function which is supposed to be (efficiently) implemented by the native | |
783 | // window class | |
784 | // ---------------------------------------------------------------------------- | |
785 | ||
786 | void wxWindow::RefreshScrollbars() | |
787 | { | |
788 | if ( m_scrollbarHorz ) | |
789 | m_scrollbarHorz->Refresh(); | |
790 | ||
791 | if ( m_scrollbarVert ) | |
792 | m_scrollbarVert->Refresh(); | |
793 | } | |
794 | ||
795 | void wxWindow::PositionScrollbars() | |
796 | { | |
797 | // do not use GetClientSize/Rect as it relies on the scrollbars being | |
798 | // correctly positioned | |
799 | ||
800 | wxSize size = GetSize(); | |
801 | wxBorder border = GetBorder(); | |
802 | wxRect rectBorder = m_renderer->GetBorderDimensions(border); | |
803 | bool inside = m_renderer->AreScrollbarsInsideBorder(); | |
804 | ||
805 | int height = m_scrollbarHorz ? m_scrollbarHorz->GetSize().y : 0; | |
806 | int width = m_scrollbarVert ? m_scrollbarVert->GetSize().x : 0; | |
807 | ||
808 | wxRect rectBar; | |
809 | if ( m_scrollbarVert ) | |
810 | { | |
811 | rectBar.x = size.x - width; | |
812 | if ( inside ) | |
813 | rectBar.x -= rectBorder.width; | |
814 | rectBar.width = width; | |
815 | rectBar.y = 0; | |
816 | if ( inside ) | |
817 | rectBar.y += rectBorder.y; | |
818 | rectBar.height = size.y - height; | |
819 | if ( inside ) | |
820 | rectBar.height -= rectBorder.y + rectBorder.height; | |
821 | ||
822 | m_scrollbarVert->SetSize(rectBar, wxSIZE_NO_ADJUSTMENTS); | |
823 | } | |
824 | ||
825 | if ( m_scrollbarHorz ) | |
826 | { | |
827 | rectBar.y = size.y - height; | |
828 | if ( inside ) | |
829 | rectBar.y -= rectBorder.height; | |
830 | rectBar.height = height; | |
831 | rectBar.x = 0; | |
832 | if ( inside ) | |
833 | rectBar.x += rectBorder.x; | |
834 | rectBar.width = size.x - width; | |
835 | if ( inside ) | |
836 | rectBar.width -= rectBorder.x + rectBorder.width; | |
837 | ||
838 | m_scrollbarHorz->SetSize(rectBar, wxSIZE_NO_ADJUSTMENTS); | |
839 | } | |
840 | ||
841 | RefreshScrollbars(); | |
842 | } | |
843 | ||
844 | void wxWindow::SetScrollbar(int orient, | |
845 | int pos, | |
846 | int pageSize, | |
847 | int range, | |
848 | bool refresh) | |
849 | { | |
3f393e3d VZ |
850 | wxASSERT_MSG( pageSize <= range, |
851 | _T("page size can't be greater than range") ); | |
852 | ||
a290fa5a | 853 | bool hasClientSizeChanged = false; |
1e6feb95 | 854 | wxScrollBar *scrollbar = GetScrollbar(orient); |
3f393e3d | 855 | if ( range && (pageSize < range) ) |
1e6feb95 VZ |
856 | { |
857 | if ( !scrollbar ) | |
858 | { | |
859 | // create it | |
ab6b6b15 | 860 | #if wxUSE_TWO_WINDOWS |
a290fa5a | 861 | SetInsertIntoMain( true ); |
ab6b6b15 | 862 | #endif |
a290fa5a | 863 | scrollbar = new wxScrollBar(this, wxID_ANY, |
1e6feb95 VZ |
864 | wxDefaultPosition, wxDefaultSize, |
865 | orient & wxVERTICAL ? wxSB_VERTICAL | |
866 | : wxSB_HORIZONTAL); | |
ab6b6b15 | 867 | #if wxUSE_TWO_WINDOWS |
a290fa5a | 868 | SetInsertIntoMain( false ); |
ab6b6b15 | 869 | #endif |
1e6feb95 VZ |
870 | if ( orient & wxVERTICAL ) |
871 | m_scrollbarVert = scrollbar; | |
872 | else | |
873 | m_scrollbarHorz = scrollbar; | |
874 | ||
875 | // the client area diminished as we created a scrollbar | |
a290fa5a | 876 | hasClientSizeChanged = true; |
1e6feb95 VZ |
877 | |
878 | PositionScrollbars(); | |
879 | } | |
880 | else if ( GetWindowStyle() & wxALWAYS_SHOW_SB ) | |
881 | { | |
882 | // we might have disabled it before | |
883 | scrollbar->Enable(); | |
884 | } | |
885 | ||
886 | scrollbar->SetScrollbar(pos, pageSize, range, pageSize, refresh); | |
887 | } | |
888 | else // no range means no scrollbar | |
889 | { | |
890 | if ( scrollbar ) | |
891 | { | |
892 | // wxALWAYS_SHOW_SB only applies to the vertical scrollbar | |
893 | if ( (orient & wxVERTICAL) && (GetWindowStyle() & wxALWAYS_SHOW_SB) ) | |
894 | { | |
895 | // just disable the scrollbar | |
896 | scrollbar->SetScrollbar(pos, pageSize, range, pageSize, refresh); | |
897 | scrollbar->Disable(); | |
898 | } | |
899 | else // really remove the scrollbar | |
900 | { | |
901 | delete scrollbar; | |
902 | ||
903 | if ( orient & wxVERTICAL ) | |
904 | m_scrollbarVert = NULL; | |
905 | else | |
906 | m_scrollbarHorz = NULL; | |
907 | ||
908 | // the client area increased as we removed a scrollbar | |
a290fa5a | 909 | hasClientSizeChanged = true; |
1e6feb95 VZ |
910 | |
911 | // the size of the remaining scrollbar must be adjusted | |
912 | if ( m_scrollbarHorz || m_scrollbarVert ) | |
913 | { | |
914 | PositionScrollbars(); | |
915 | } | |
916 | } | |
917 | } | |
918 | } | |
919 | ||
920 | // give the window a chance to relayout | |
921 | if ( hasClientSizeChanged ) | |
922 | { | |
a17a79ba RR |
923 | #if wxUSE_TWO_WINDOWS |
924 | wxWindowNative::SetSize( GetSize() ); | |
925 | #else | |
1e6feb95 VZ |
926 | wxSizeEvent event(GetSize()); |
927 | (void)GetEventHandler()->ProcessEvent(event); | |
a17a79ba | 928 | #endif |
1e6feb95 VZ |
929 | } |
930 | } | |
931 | ||
61fef19b | 932 | void wxWindow::SetScrollPos(int orient, int pos, bool WXUNUSED(refresh)) |
1e6feb95 VZ |
933 | { |
934 | wxScrollBar *scrollbar = GetScrollbar(orient); | |
935 | wxCHECK_RET( scrollbar, _T("no scrollbar to set position for") ); | |
936 | ||
937 | scrollbar->SetThumbPosition(pos); | |
7d297414 VZ |
938 | |
939 | // VZ: I think we can safely ignore this as we always refresh it | |
940 | // automatically whenever the value chanegs | |
941 | #if 0 | |
1e6feb95 VZ |
942 | if ( refresh ) |
943 | Refresh(); | |
7d297414 | 944 | #endif |
1e6feb95 VZ |
945 | } |
946 | ||
947 | int wxWindow::GetScrollPos(int orient) const | |
948 | { | |
949 | wxScrollBar *scrollbar = GetScrollbar(orient); | |
950 | return scrollbar ? scrollbar->GetThumbPosition() : 0; | |
951 | } | |
952 | ||
953 | int wxWindow::GetScrollThumb(int orient) const | |
954 | { | |
955 | wxScrollBar *scrollbar = GetScrollbar(orient); | |
956 | return scrollbar ? scrollbar->GetThumbSize() : 0; | |
957 | } | |
958 | ||
959 | int wxWindow::GetScrollRange(int orient) const | |
960 | { | |
961 | wxScrollBar *scrollbar = GetScrollbar(orient); | |
962 | return scrollbar ? scrollbar->GetRange() : 0; | |
963 | } | |
964 | ||
965 | void wxWindow::ScrollWindow(int dx, int dy, const wxRect *rect) | |
966 | { | |
66a58655 VS |
967 | // use native scrolling when available and do it in generic way |
968 | // otherwise: | |
4125131b RR |
969 | #ifdef __WXX11__ |
970 | ||
66a58655 | 971 | wxWindowNative::ScrollWindow(dx, dy, rect); |
4125131b | 972 | |
2b5f62a0 | 973 | #else // !wxX11 |
4125131b | 974 | |
1e6feb95 VZ |
975 | // before scrolling it, ensure that we don't have any unpainted areas |
976 | Update(); | |
977 | ||
978 | wxRect r; | |
979 | ||
980 | if ( dx ) | |
981 | { | |
982 | r = ScrollNoRefresh(dx, 0, rect); | |
a290fa5a | 983 | Refresh(true /* erase bkgnd */, &r); |
1e6feb95 VZ |
984 | } |
985 | ||
986 | if ( dy ) | |
987 | { | |
988 | r = ScrollNoRefresh(0, dy, rect); | |
a290fa5a | 989 | Refresh(true /* erase bkgnd */, &r); |
1e6feb95 | 990 | } |
2b5f62a0 VZ |
991 | |
992 | // scroll children accordingly: | |
66a58655 | 993 | wxPoint offset(dx, dy); |
2b5f62a0 | 994 | |
ac32ba44 | 995 | for (wxWindowList::compatibility_iterator node = GetChildren().GetFirst(); |
66a58655 VS |
996 | node; node = node->GetNext()) |
997 | { | |
998 | wxWindow *child = node->GetData(); | |
1c9f1f4d VS |
999 | if ( child == m_scrollbarVert || child == m_scrollbarHorz ) |
1000 | continue; | |
1001 | ||
1002 | // VS: Scrolling children has non-trivial semantics. If rect=NULL then | |
2b5f62a0 | 1003 | // it is easy: we scroll all children. Otherwise it gets |
1c9f1f4d VS |
1004 | // complicated: |
1005 | // 1. if scrolling in one direction only, scroll only | |
1006 | // those children that intersect shaft defined by the rectangle | |
1007 | // and scrolling direction | |
1008 | // 2. if scrolling in both axes, scroll all children | |
2b5f62a0 | 1009 | |
1c9f1f4d VS |
1010 | if ( rect && (dx * dy == 0 /* moving in only one of x, y axis */) ) |
1011 | { | |
1012 | wxRect childRect = child->GetRect(); | |
1013 | if ( dx == 0 && (childRect.GetLeft() <= rect->GetRight() || | |
1014 | childRect.GetRight() >= rect->GetLeft()) ) | |
1015 | { | |
1016 | child->Move(child->GetPosition() + offset); | |
1017 | } | |
1018 | else if ( dy == 0 && (childRect.GetTop() <= rect->GetBottom() || | |
1019 | childRect.GetBottom() >= rect->GetTop()) ) | |
1020 | { | |
1021 | child->Move(child->GetPosition() + offset); | |
1022 | } | |
1023 | } | |
1024 | else | |
66a58655 VS |
1025 | { |
1026 | child->Move(child->GetPosition() + offset); | |
1027 | } | |
2b5f62a0 VZ |
1028 | } |
1029 | #endif // wxX11/!wxX11 | |
1e6feb95 VZ |
1030 | } |
1031 | ||
1032 | wxRect wxWindow::ScrollNoRefresh(int dx, int dy, const wxRect *rectTotal) | |
1033 | { | |
1034 | wxASSERT_MSG( !dx || !dy, _T("can't be used for diag scrolling") ); | |
1035 | ||
1036 | // the rect to refresh (which we will calculate) | |
1037 | wxRect rect; | |
1038 | ||
1039 | if ( !dx && !dy ) | |
1040 | { | |
1041 | // nothing to do | |
1042 | return rect; | |
1043 | } | |
1044 | ||
1045 | // calculate the part of the window which we can just redraw in the new | |
1046 | // location | |
1047 | wxSize sizeTotal = rectTotal ? rectTotal->GetSize() : GetClientSize(); | |
1048 | ||
1049 | wxLogTrace(_T("scroll"), _T("rect is %dx%d, scroll by %d, %d"), | |
1050 | sizeTotal.x, sizeTotal.y, dx, dy); | |
1051 | ||
1052 | // the initial and end point of the region we move in client coords | |
1053 | wxPoint ptSource, ptDest; | |
1054 | if ( rectTotal ) | |
1055 | { | |
1056 | ptSource = rectTotal->GetPosition(); | |
1057 | ptDest = rectTotal->GetPosition(); | |
1058 | } | |
1059 | ||
1060 | // the size of this region | |
1061 | wxSize size; | |
1062 | size.x = sizeTotal.x - abs(dx); | |
1063 | size.y = sizeTotal.y - abs(dy); | |
1064 | if ( size.x <= 0 || size.y <= 0 ) | |
1065 | { | |
1066 | // just redraw everything as nothing of the displayed image will stay | |
1067 | wxLogTrace(_T("scroll"), _T("refreshing everything")); | |
1068 | ||
1069 | rect = rectTotal ? *rectTotal : wxRect(0, 0, sizeTotal.x, sizeTotal.y); | |
1070 | } | |
1071 | else // move the part which doesn't change to the new location | |
1072 | { | |
1073 | // note that when we scroll the canvas in some direction we move the | |
1074 | // block which doesn't need to be refreshed in the opposite direction | |
1075 | ||
1076 | if ( dx < 0 ) | |
1077 | { | |
1078 | // scroll to the right, move to the left | |
1079 | ptSource.x -= dx; | |
1080 | } | |
1081 | else | |
1082 | { | |
1083 | // scroll to the left, move to the right | |
1084 | ptDest.x += dx; | |
1085 | } | |
1086 | ||
1087 | if ( dy < 0 ) | |
1088 | { | |
1089 | // scroll down, move up | |
1090 | ptSource.y -= dy; | |
1091 | } | |
1092 | else | |
1093 | { | |
1094 | // scroll up, move down | |
1095 | ptDest.y += dy; | |
1096 | } | |
1097 | ||
1098 | #if wxUSE_CARET | |
1099 | // we need to hide the caret before moving or it will erase itself at | |
1100 | // the wrong (old) location | |
1101 | wxCaret *caret = GetCaret(); | |
1102 | if ( caret ) | |
1103 | caret->Hide(); | |
1104 | #endif // wxUSE_CARET | |
1105 | ||
1106 | // do move | |
1107 | wxClientDC dc(this); | |
1108 | wxBitmap bmp(size.x, size.y); | |
1109 | wxMemoryDC dcMem; | |
1110 | dcMem.SelectObject(bmp); | |
1111 | ||
c47addef | 1112 | dcMem.Blit(wxPoint(0,0), size, &dc, ptSource |
03147cd0 | 1113 | #if defined(__WXGTK__) && !defined(wxHAS_WORKING_GTK_DC_BLIT) |
1e6feb95 VZ |
1114 | + GetClientAreaOrigin() |
1115 | #endif // broken wxGTK wxDC::Blit | |
1116 | ); | |
c47addef | 1117 | dc.Blit(ptDest, size, &dcMem, wxPoint(0,0)); |
1e6feb95 VZ |
1118 | |
1119 | wxLogTrace(_T("scroll"), | |
1120 | _T("Blit: (%d, %d) of size %dx%d -> (%d, %d)"), | |
1121 | ptSource.x, ptSource.y, | |
1122 | size.x, size.y, | |
1123 | ptDest.x, ptDest.y); | |
1124 | ||
1125 | // and now repaint the uncovered area | |
1126 | ||
1127 | // FIXME: We repaint the intersection of these rectangles twice - is | |
1128 | // it bad? I don't think so as it is rare to scroll the window | |
1129 | // diagonally anyhow and so adding extra logic to compute | |
1130 | // rectangle intersection is probably not worth the effort | |
1131 | ||
1132 | rect.x = ptSource.x; | |
1133 | rect.y = ptSource.y; | |
1134 | ||
1135 | if ( dx ) | |
1136 | { | |
1137 | if ( dx < 0 ) | |
1138 | { | |
1139 | // refresh the area along the right border | |
1140 | rect.x += size.x + dx; | |
1141 | rect.width = -dx; | |
1142 | } | |
1143 | else | |
1144 | { | |
1145 | // refresh the area along the left border | |
1146 | rect.width = dx; | |
1147 | } | |
1148 | ||
1149 | rect.height = sizeTotal.y; | |
1150 | ||
1151 | wxLogTrace(_T("scroll"), _T("refreshing (%d, %d)-(%d, %d)"), | |
1152 | rect.x, rect.y, | |
1153 | rect.GetRight() + 1, rect.GetBottom() + 1); | |
1154 | } | |
1155 | ||
1156 | if ( dy ) | |
1157 | { | |
1158 | if ( dy < 0 ) | |
1159 | { | |
1160 | // refresh the area along the bottom border | |
1161 | rect.y += size.y + dy; | |
1162 | rect.height = -dy; | |
1163 | } | |
1164 | else | |
1165 | { | |
1166 | // refresh the area along the top border | |
1167 | rect.height = dy; | |
1168 | } | |
1169 | ||
1170 | rect.width = sizeTotal.x; | |
1171 | ||
1172 | wxLogTrace(_T("scroll"), _T("refreshing (%d, %d)-(%d, %d)"), | |
1173 | rect.x, rect.y, | |
1174 | rect.GetRight() + 1, rect.GetBottom() + 1); | |
1175 | } | |
1176 | ||
1177 | #if wxUSE_CARET | |
1178 | if ( caret ) | |
1179 | caret->Show(); | |
1180 | #endif // wxUSE_CARET | |
1181 | } | |
1182 | ||
1183 | return rect; | |
1184 | } | |
1185 | ||
1e6feb95 VZ |
1186 | // ---------------------------------------------------------------------------- |
1187 | // accelerators and menu hot keys | |
1188 | // ---------------------------------------------------------------------------- | |
1189 | ||
1190 | #if wxUSE_MENUS | |
1191 | // the last window over which Alt was pressed (used by OnKeyUp) | |
1192 | wxWindow *wxWindow::ms_winLastAltPress = NULL; | |
1193 | #endif // wxUSE_MENUS | |
1194 | ||
1195 | #if wxUSE_ACCEL || wxUSE_MENUS | |
1196 | ||
1197 | void wxWindow::OnKeyDown(wxKeyEvent& event) | |
1198 | { | |
1199 | #if wxUSE_MENUS | |
1200 | int key = event.GetKeyCode(); | |
f52c3131 | 1201 | if ( !event.ControlDown() && (key == WXK_ALT || key == WXK_F10) ) |
1e6feb95 VZ |
1202 | { |
1203 | ms_winLastAltPress = this; | |
1204 | ||
1205 | // it can't be an accel anyhow | |
1206 | return; | |
1207 | } | |
1208 | ||
1209 | ms_winLastAltPress = NULL; | |
1210 | #endif // wxUSE_MENUS | |
1211 | ||
1212 | #if wxUSE_ACCEL | |
1213 | for ( wxWindow *win = this; win; win = win->GetParent() ) | |
1214 | { | |
1215 | int command = win->GetAcceleratorTable()->GetCommand(event); | |
1216 | if ( command != -1 ) | |
1217 | { | |
1218 | wxCommandEvent eventCmd(wxEVT_COMMAND_MENU_SELECTED, command); | |
1219 | if ( win->GetEventHandler()->ProcessEvent(eventCmd) ) | |
1220 | { | |
1221 | // skip "event.Skip()" below | |
1222 | return; | |
1223 | } | |
1224 | } | |
1225 | ||
1226 | if ( win->IsTopLevel() ) | |
1227 | { | |
1228 | // try the frame menu bar | |
1229 | #if wxUSE_MENUS | |
1230 | wxFrame *frame = wxDynamicCast(win, wxFrame); | |
1231 | if ( frame ) | |
1232 | { | |
1233 | wxMenuBar *menubar = frame->GetMenuBar(); | |
1234 | if ( menubar && menubar->ProcessAccelEvent(event) ) | |
1235 | { | |
1236 | // skip "event.Skip()" below | |
1237 | return; | |
1238 | } | |
1239 | } | |
1240 | #endif // wxUSE_MENUS | |
1241 | ||
81762e79 VS |
1242 | // if it wasn't in a menu, try to find a button |
1243 | if ( command != -1 ) | |
1244 | { | |
1245 | wxWindow* child = win->FindWindow(command); | |
1246 | if ( child && wxDynamicCast(child, wxButton) ) | |
1247 | { | |
1248 | wxCommandEvent eventCmd(wxEVT_COMMAND_BUTTON_CLICKED, command); | |
1249 | eventCmd.SetEventObject(child); | |
1250 | if ( child->GetEventHandler()->ProcessEvent(eventCmd) ) | |
1251 | { | |
1252 | // skip "event.Skip()" below | |
1253 | return; | |
1254 | } | |
1255 | } | |
1256 | } | |
1257 | ||
1e6feb95 VZ |
1258 | // don't propagate accels from the child frame to the parent one |
1259 | break; | |
1260 | } | |
1261 | } | |
1262 | #endif // wxUSE_ACCEL | |
1263 | ||
1264 | event.Skip(); | |
1265 | } | |
1266 | ||
1267 | #endif // wxUSE_ACCEL | |
1268 | ||
1269 | #if wxUSE_MENUS | |
1270 | ||
1271 | wxMenuBar *wxWindow::GetParentFrameMenuBar() const | |
1272 | { | |
1273 | for ( const wxWindow *win = this; win; win = win->GetParent() ) | |
1274 | { | |
1275 | if ( win->IsTopLevel() ) | |
1276 | { | |
1277 | wxFrame *frame = wxDynamicCast(win, wxFrame); | |
1278 | if ( frame ) | |
1279 | { | |
1280 | return frame->GetMenuBar(); | |
1281 | } | |
1282 | ||
1283 | // don't look further - we don't want to return the menubar of the | |
1284 | // parent frame | |
1285 | break; | |
1286 | } | |
1287 | } | |
1288 | ||
1289 | return NULL; | |
1290 | } | |
1291 | ||
1292 | void wxWindow::OnChar(wxKeyEvent& event) | |
1293 | { | |
1294 | if ( event.AltDown() && !event.ControlDown() ) | |
1295 | { | |
1296 | int key = event.GetKeyCode(); | |
1297 | ||
1298 | wxMenuBar *menubar = GetParentFrameMenuBar(); | |
1299 | if ( menubar ) | |
1300 | { | |
1301 | int item = menubar->FindNextItemForAccel(-1, key); | |
1302 | if ( item != -1 ) | |
1303 | { | |
1304 | menubar->PopupMenu((size_t)item); | |
1305 | ||
1306 | // skip "event.Skip()" below | |
1307 | return; | |
1308 | } | |
1309 | } | |
1310 | } | |
1311 | ||
1312 | event.Skip(); | |
1313 | } | |
1314 | ||
1315 | void wxWindow::OnKeyUp(wxKeyEvent& event) | |
1316 | { | |
1317 | int key = event.GetKeyCode(); | |
f52c3131 | 1318 | if ( !event.HasModifiers() && (key == WXK_ALT || key == WXK_F10) ) |
1e6feb95 VZ |
1319 | { |
1320 | // only process Alt release specially if there were no other key | |
1321 | // presses since Alt had been pressed and if both events happened in | |
1322 | // the same window | |
1323 | if ( ms_winLastAltPress == this ) | |
1324 | { | |
1325 | wxMenuBar *menubar = GetParentFrameMenuBar(); | |
1326 | if ( menubar && this != menubar ) | |
1327 | { | |
1328 | menubar->SelectMenu(0); | |
1329 | } | |
1330 | } | |
1331 | } | |
1332 | else | |
1333 | { | |
1334 | event.Skip(); | |
1335 | } | |
1336 | ||
1337 | // in any case reset it | |
1338 | ms_winLastAltPress = NULL; | |
1339 | } | |
1340 | ||
1341 | #endif // wxUSE_MENUS | |
1342 | ||
30827629 VZ |
1343 | // ---------------------------------------------------------------------------- |
1344 | // MSW-specific section | |
1345 | // ---------------------------------------------------------------------------- | |
1346 | ||
1347 | #ifdef __WXMSW__ | |
1348 | ||
1349 | #include "wx/msw/private.h" | |
1350 | ||
c140b7e7 | 1351 | WXLRESULT wxWindow::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam) |
30827629 VZ |
1352 | { |
1353 | if ( message == WM_NCHITTEST ) | |
1354 | { | |
1355 | // the windows which contain the other windows should let the mouse | |
1356 | // events through, otherwise a window inside a static box would | |
1357 | // never get any events at all | |
1358 | if ( IsStaticBox() ) | |
1359 | { | |
1360 | return HTTRANSPARENT; | |
1361 | } | |
1362 | } | |
1363 | ||
1364 | return wxWindowNative::MSWWindowProc(message, wParam, lParam); | |
1365 | } | |
1366 | ||
1367 | #endif // __WXMSW__ |