~ubuntu-branches/ubuntu/maverick/wxwidgets2.8/maverick-proposed

« back to all changes in this revision

Viewing changes to src/mac/carbon/window.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Devid Filoni
  • Date: 2007-11-06 18:25:13 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20071106182513-809agqds6igh7mqo
Tags: 2.8.6.1-0ubuntu1
* New upstream version, based on the upstream tarball
  wxPython-src-2.8.6.1.tar.bz2, renamed debian to debian-upstream.
* Provide a get-orig-source target to do the repackaging.
* Fix "substvar-source-version-is-deprecated" lintian warnings.
* Remove duplicate Description field in debian/control.
* Add "\" at the end of line 8 in debian/python-wxtools.menu to fix
  "bad-test-in-menu-item" lintian error.
* Provide .xpm icons to fix "menu-icon-not-in-xpm-format" lintian errors,
  changed Icon field in debian/python-wxtools.menu.
* Fix "wrong-name-for-upstream-changelog" lintian warnings.
* Remove "Application;" from Categories field in debian/pycrust.desktop,
  debian/pyshell.desktop, debian/xrced.desktop.
* Switch "Apps" to "Applications" in debian/python-wxtools.menu to fix
  "menu-item-uses-apps-section" lintian warnings.
* Drop the icon extension from debian/pycrust.desktop,
  debian/pyshell.desktop, debian/xrced.desktop.
* Add dpatch support.
* Add "WX_CONFIG" patch.
* debian/rules:
  - added .xpm icons to install-gtk-py-tools target
  - added "docs/changes.txt" to dh_installchangelogs in binary-common target
  - added "\" at the end of "install-examples install-msw-dev
    install-msw-dbg install-headers-msw" line in .PHONY

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
// Author:      Stefan Csomor
5
5
// Modified by:
6
6
// Created:     1998-01-01
7
 
// RCS-ID:      $Id: window.cpp,v 1.326.2.3 2007/05/02 13:58:00 SC Exp $
 
7
// RCS-ID:      $Id: window.cpp 49305 2007-10-21 18:14:52Z SC $
8
8
// Copyright:   (c) Stefan Csomor
9
9
// Licence:     wxWindows licence
10
10
/////////////////////////////////////////////////////////////////////////////
53
53
    #include "wx/caret.h"
54
54
#endif
55
55
 
 
56
#if wxUSE_POPUPWIN
 
57
    #include "wx/popupwin.h"
 
58
#endif
 
59
 
56
60
#if wxUSE_DRAG_AND_DROP
57
61
#include "wx/dnd.h"
58
62
#endif
65
69
#ifndef __DARWIN__
66
70
#include <Windows.h>
67
71
#include <ToolUtils.h>
68
 
#include <Scrap.h>
69
72
#include <MacTextEditor.h>
70
73
#endif
71
74
 
122
125
//
123
126
 
124
127
 
125
 
void wxMacNativeToWindow( const wxWindow* window , RgnHandle handle )
 
128
void wxMacNativeToWindow( const wxWindowMac* window , RgnHandle handle )
126
129
{
127
130
    OffsetRgn( handle , window->MacGetLeftBorderSize() , window->MacGetTopBorderSize() ) ;
128
131
}
129
132
 
130
 
void wxMacNativeToWindow( const wxWindow* window , Rect *rect )
 
133
void wxMacNativeToWindow( const wxWindowMac* window , Rect *rect )
131
134
{
132
135
    OffsetRect( rect , window->MacGetLeftBorderSize() , window->MacGetTopBorderSize() ) ;
133
136
}
136
139
// directed towards native control
137
140
//
138
141
 
139
 
void wxMacWindowToNative( const wxWindow* window , RgnHandle handle )
 
142
void wxMacWindowToNative( const wxWindowMac* window , RgnHandle handle )
140
143
{
141
144
    OffsetRgn( handle , -window->MacGetLeftBorderSize() , -window->MacGetTopBorderSize() );
142
145
}
143
146
 
144
 
void wxMacWindowToNative( const wxWindow* window , Rect *rect )
 
147
void wxMacWindowToNative( const wxWindowMac* window , Rect *rect )
145
148
{
146
149
    OffsetRect( rect , -window->MacGetLeftBorderSize() , -window->MacGetTopBorderSize() ) ;
147
150
}
267
270
                        wxMacCGContextStateSaver sg( cgContext ) ;
268
271
                        float alpha = 1.0 ;
269
272
                        {
270
 
                            wxWindow* iter = thisWindow ;
271
 
                            while ( iter ) 
 
273
                            wxWindowMac* iter = thisWindow ;
 
274
                            while ( iter )
272
275
                            {
273
276
                                alpha *= (float) iter->GetTransparent()/255.0 ;
274
277
                                if ( iter->IsTopLevel() )
307
310
        case kEventControlHiliteChanged :
308
311
            thisWindow->MacHiliteChanged() ;
309
312
            break ;
310
 
            
 
313
 
311
314
        case kEventControlActivate :
312
315
        case kEventControlDeactivate :
313
316
            // FIXME: we should have a virtual function for this!
358
361
                else
359
362
                {
360
363
                    // panel wants to track the window which was the last to have focus in it
361
 
                    wxChildFocusEvent eventFocus(thisWindow);
 
364
                    wxChildFocusEvent eventFocus((wxWindow*)thisWindow);
362
365
                    thisWindow->GetEventHandler()->ProcessEvent(eventFocus);
363
366
 
364
367
#if wxUSE_CARET
379
382
 
380
383
        case kEventControlGetClickActivation :
381
384
            {
382
 
                // fix to always have a proper activation for DataBrowser controls (stay in bkgnd otherwise)
 
385
                // fix to always have a proper activation for DataBrowser controls (stay in bkgnd otherwise)
383
386
                WindowRef owner = cEvent.GetParameter<WindowRef>(kEventParamWindowRef);
384
387
                if ( !IsWindowActive(owner) )
385
388
                {
448
451
                textCtrl->GetSelection( &from , &to ) ;
449
452
                wxString val = textCtrl->GetValue() ;
450
453
                val = val.Mid( from , to - from ) ;
451
 
                ScrapRef scrapRef = cEvent.GetParameter< ScrapRef > ( kEventParamScrapRef , typeScrapRef ) ;
452
 
                verify_noerr( ClearScrap( &scrapRef ) ) ;
453
 
                verify_noerr( PutScrapFlavor( scrapRef , kTXNTextData , 0 , val.length() , val.c_str() ) ) ;
 
454
                PasteboardRef pasteboard = cEvent.GetParameter<PasteboardRef>( kEventParamPasteboardRef, typePasteboardRef );
 
455
                verify_noerr( PasteboardClear( pasteboard ) ) ;
 
456
                PasteboardSynchronize( pasteboard );
 
457
                CFDataRef data = CFDataCreate( kCFAllocatorDefault, (UInt8*)val.c_str(), val.length() );
 
458
                PasteboardPutItemFlavor( pasteboard, (PasteboardItemID) 1, CFSTR("com.apple.traditional-mac-plain-text"), data, 0);
 
459
                CFRelease( data );
454
460
                result = noErr ;
455
461
            }
456
462
            break ;
458
464
        case kEventServicePaste :
459
465
            if ( textCtrl )
460
466
            {
461
 
                ScrapRef scrapRef = cEvent.GetParameter< ScrapRef > ( kEventParamScrapRef , typeScrapRef ) ;
462
 
                Size textSize, pastedSize ;
463
 
                verify_noerr( GetScrapFlavorSize(scrapRef, kTXNTextData, &textSize) ) ;
464
 
                textSize++ ;
465
 
                char *content = new char[textSize] ;
466
 
                GetScrapFlavorData(scrapRef, kTXNTextData, &pastedSize, content );
467
 
                content[textSize - 1] = 0 ;
468
 
 
 
467
                PasteboardRef pasteboard = cEvent.GetParameter<PasteboardRef>( kEventParamPasteboardRef, typePasteboardRef );
 
468
                PasteboardSynchronize( pasteboard );
 
469
                ItemCount itemCount;
 
470
                verify_noerr( PasteboardGetItemCount( pasteboard, &itemCount ) );
 
471
                for( UInt32 itemIndex = 1; itemIndex <= itemCount; itemIndex++ )
 
472
                {
 
473
                    PasteboardItemID itemID;
 
474
                    if ( PasteboardGetItemIdentifier( pasteboard, itemIndex, &itemID ) == noErr )
 
475
                    {
 
476
                        CFDataRef flavorData = NULL;
 
477
                        if ( PasteboardCopyItemFlavorData( pasteboard, itemID, CFSTR("com.apple.traditional-mac-plain-text"), &flavorData ) == noErr )
 
478
                        {
 
479
                            CFIndex flavorDataSize = CFDataGetLength( flavorData );
 
480
                            char *content = new char[flavorDataSize+1] ;
 
481
                            memcpy( content, CFDataGetBytePtr( flavorData ), flavorDataSize );
 
482
                            content[flavorDataSize]=0;
 
483
                            CFRelease( flavorData );
469
484
#if wxUSE_UNICODE
470
 
                textCtrl->WriteText( wxString( content , wxConvLocal ) );
 
485
                            textCtrl->WriteText( wxString( content , wxConvLocal ) );
471
486
#else
472
 
                textCtrl->WriteText( wxString( content ) ) ;
 
487
                            textCtrl->WriteText( wxString( content ) ) ;
473
488
#endif
474
489
 
475
 
                delete[] content ;
476
 
                result = noErr ;
477
 
            }
 
490
                            delete[] content ;
 
491
                            result = noErr ;
 
492
                        }
 
493
                    }
 
494
                }
 
495
           }
478
496
            break ;
479
497
 
480
498
        default:
511
529
        charBuf[ numChars - 1 ] = 0;
512
530
#if SIZEOF_WCHAR_T == 2
513
531
        uniChars = (wchar_t*) charBuf ;
514
 
/*        memcpy( uniChars , charBuf , numChars * 2 ) ;*/       // is there any point in copying charBuf over itself? (in fact, memcpy isn't even guaranteed to work correctly if the source and destination ranges overlap...)
 
532
/*        memcpy( uniChars , charBuf , numChars * 2 ) ;*/   // is there any point in copying charBuf over itself? (in fact, memcpy isn't even guaranteed to work correctly if the source and destination ranges overlap...)
515
533
#else
516
534
        // the resulting string will never have more chars than the utf16 version, so this is safe
517
535
        wxMBConvUTF16 converter ;
533
551
 
534
552
                    UInt32 message = uniChars[pos] < 128 ? (char)uniChars[pos] : '?';
535
553
/*
536
 
        NB: faking a charcode here is problematic. The kEventTextInputUpdateActiveInputArea event is sent
537
 
        multiple times to update the active range during inline input, so this handler will often receive
538
 
        uncommited text, which should usually not trigger side effects. It might be a good idea to check the
539
 
        kEventParamTextInputSendFixLen parameter and verify if input is being confirmed (see CarbonEvents.h).
540
 
        On the other hand, it can be useful for some applications to react to uncommitted text (for example,
541
 
        to update a status display), as long as it does not disrupt the inline input session. Ideally, wx
542
 
        should add new event types to support advanced text input. For now, I would keep things as they are.
543
 
        
544
 
        However, the code that was being used caused additional problems:
 
554
    NB: faking a charcode here is problematic. The kEventTextInputUpdateActiveInputArea event is sent
 
555
    multiple times to update the active range during inline input, so this handler will often receive
 
556
    uncommited text, which should usually not trigger side effects. It might be a good idea to check the
 
557
    kEventParamTextInputSendFixLen parameter and verify if input is being confirmed (see CarbonEvents.h).
 
558
    On the other hand, it can be useful for some applications to react to uncommitted text (for example,
 
559
    to update a status display), as long as it does not disrupt the inline input session. Ideally, wx
 
560
    should add new event types to support advanced text input. For now, I would keep things as they are.
 
561
 
 
562
    However, the code that was being used caused additional problems:
545
563
                    UInt32 message = (0  << 8) + ((char)uniChars[pos] );
546
 
        Since it simply truncated the unichar to the last byte, it ended up causing weird bugs with inline
547
 
        input, such as switching to another field when one attempted to insert the character U+4E09 (the kanji
548
 
        for "three"), because it was truncated to 09 (kTabCharCode), which was later "converted" to WXK_TAB
549
 
        (still 09) in wxMacTranslateKey; or triggering the default button when one attempted to insert U+840D
550
 
        (the kanji for "name"), which got truncated to 0D and interpreted as a carriage return keypress.
551
 
        Note that even single-byte characters could have been misinterpreted, since MacRoman charcodes only
552
 
        overlap with Unicode within the (7-bit) ASCII range.
553
 
        But simply passing a NUL charcode would disable text updated events, because wxTextCtrl::OnChar checks
554
 
        for codes within a specific range. Therefore I went for the solution seen above, which keeps ASCII
555
 
        characters as they are and replaces the rest with '?', ensuring that update events are triggered.
556
 
        It would be better to change wxTextCtrl::OnChar to look at the actual unicode character instead, but
557
 
        I don't have time to look into that right now.
558
 
                -- CL
 
564
    Since it simply truncated the unichar to the last byte, it ended up causing weird bugs with inline
 
565
    input, such as switching to another field when one attempted to insert the character U+4E09 (the kanji
 
566
    for "three"), because it was truncated to 09 (kTabCharCode), which was later "converted" to WXK_TAB
 
567
    (still 09) in wxMacTranslateKey; or triggering the default button when one attempted to insert U+840D
 
568
    (the kanji for "name"), which got truncated to 0D and interpreted as a carriage return keypress.
 
569
    Note that even single-byte characters could have been misinterpreted, since MacRoman charcodes only
 
570
    overlap with Unicode within the (7-bit) ASCII range.
 
571
    But simply passing a NUL charcode would disable text updated events, because wxTextCtrl::OnChar checks
 
572
    for codes within a specific range. Therefore I went for the solution seen above, which keeps ASCII
 
573
    characters as they are and replaces the rest with '?', ensuring that update events are triggered.
 
574
    It would be better to change wxTextCtrl::OnChar to look at the actual unicode character instead, but
 
575
    I don't have time to look into that right now.
 
576
        -- CL
559
577
*/
560
 
                    if ( wxTheApp->MacSendCharEvent(
 
578
                    if ( wxTheApp->MacSendCharEvent((wxWindow*)
561
579
                                                    focus , message , 0 , when , 0 , 0 , uniChars[pos] ) )
562
580
                    {
563
581
                        result = noErr ;
590
608
                    WXEVENTHANDLERCALLREF formerHandler = wxTheApp->MacGetCurrentEventHandlerCallRef() ;
591
609
                    wxTheApp->MacSetCurrentEvent( event , handler ) ;
592
610
 
593
 
                    if ( wxTheApp->MacSendCharEvent(
 
611
                    if ( wxTheApp->MacSendCharEvent((wxWindow*)
594
612
                        focus , message , modifiers , when , point.h , point.v , uniChars[pos] ) )
595
613
                    {
596
614
                        result = noErr ;
633
651
        {
634
652
            case kEventProcessCommand :
635
653
                {
 
654
                    // HiliteMenu(0);
636
655
                    if (item->IsCheckable())
637
656
                        item->Check( !item->IsChecked() ) ;
638
657
 
882
901
{
883
902
    if ( partCode != 0)
884
903
    {
885
 
        wxWindow*  wx = wxFindControlFromMacControl( control ) ;
 
904
        wxWindowMac*  wx = wxFindControlFromMacControl( control ) ;
886
905
        if ( wx )
887
906
            wx->MacHandleControlClick( (WXWidget) control , partCode , true /* stillDown */ ) ;
888
907
    }
893
912
// implementation
894
913
// ===========================================================================
895
914
 
896
 
WX_DECLARE_HASH_MAP(ControlRef, wxWindow*, wxPointerHash, wxPointerEqual, MacControlMap);
 
915
WX_DECLARE_HASH_MAP(ControlRef, wxWindowMac*, wxPointerHash, wxPointerEqual, MacControlMap);
897
916
 
898
917
static MacControlMap wxWinMacControlList;
899
918
 
900
 
wxWindow *wxFindControlFromMacControl(ControlRef inControl )
 
919
wxWindowMac *wxFindControlFromMacControl(ControlRef inControl )
901
920
{
902
921
    MacControlMap::iterator node = wxWinMacControlList.find(inControl);
903
922
 
904
923
    return (node == wxWinMacControlList.end()) ? NULL : node->second;
905
924
}
906
925
 
907
 
void wxAssociateControlWithMacControl(ControlRef inControl, wxWindow *control)
 
926
void wxAssociateControlWithMacControl(ControlRef inControl, wxWindowMac *control)
908
927
{
909
928
    // adding NULL ControlRef is (first) surely a result of an error and
910
929
    // (secondly) breaks native event processing
913
932
    wxWinMacControlList[inControl] = control;
914
933
}
915
934
 
916
 
void wxRemoveMacControlAssociation(wxWindow *control)
 
935
void wxRemoveMacControlAssociation(wxWindowMac *control)
917
936
{
918
937
   // iterate over all the elements in the class
919
938
    // is the iterator stable ? as we might have two associations pointing to the same wxWindow
1013
1032
    // wxRemoveMacControlAssociation( this ) ;
1014
1033
    // If we delete an item, we should initialize the parent panel,
1015
1034
    // because it could now be invalid.
1016
 
    wxTopLevelWindow *tlw = wxDynamicCast(wxGetTopLevelParent(this), wxTopLevelWindow);
 
1035
    wxTopLevelWindow *tlw = wxDynamicCast(wxGetTopLevelParent((wxWindow*)this), wxTopLevelWindow);
1017
1036
    if ( tlw )
1018
1037
    {
1019
1038
        if ( tlw->GetDefaultItem() == (wxButton*) this)
1033
1052
    if ( g_MacLastWindow == this )
1034
1053
        g_MacLastWindow = NULL ;
1035
1054
 
1036
 
    wxFrame* frame = wxDynamicCast( wxGetTopLevelParent( this ) , wxFrame ) ;
 
1055
#ifndef __WXUNIVERSAL__
 
1056
    wxFrame* frame = wxDynamicCast( wxGetTopLevelParent( (wxWindow*)this ) , wxFrame ) ;
1037
1057
    if ( frame )
1038
1058
    {
1039
1059
        if ( frame->GetLastFocus() == this )
1040
1060
            frame->SetLastFocus( NULL ) ;
1041
1061
    }
 
1062
#endif
1042
1063
 
1043
1064
    // delete our drop target if we've got one
1044
1065
#if wxUSE_DRAG_AND_DROP
1109
1130
            | kControlWantsActivate
1110
1131
            | kControlWantsIdle ;
1111
1132
 
1112
 
        m_peer = new wxMacControl(this) ;
 
1133
        m_peer = new wxMacControl((wxWindow*)this) ;
1113
1134
        OSStatus err =::CreateUserPaneControl( MAC_WXHWND(GetParent()->MacGetTopLevelWindowRef()) , &bounds, features , m_peer->GetControlRefAddr() );
1114
1135
        verify_noerr( err );
1115
1136
 
1125
1146
    }
1126
1147
#endif
1127
1148
 
1128
 
    wxWindowCreateEvent event(this);
 
1149
    wxWindowCreateEvent event((wxWindow*)this);
1129
1150
    GetEventHandler()->AddPendingEvent(event);
1130
1151
 
1131
1152
    return true;
1228
1249
void wxWindowMac::MacUpdateControlFont()
1229
1250
{
1230
1251
    m_peer->SetFont( GetFont() , GetForegroundColour() , GetWindowStyle() ) ;
1231
 
    Refresh() ;
 
1252
    // do not trigger refreshes upon invisible and possible partly created objects
 
1253
    if ( MacIsReallyShown() )
 
1254
        Refresh() ;
1232
1255
}
1233
1256
 
1234
1257
bool wxWindowMac::SetFont(const wxFont& font)
1356
1379
 
1357
1380
void wxWindowMac::DoCaptureMouse()
1358
1381
{
1359
 
    wxApp::s_captureWindow = this ;
 
1382
    wxApp::s_captureWindow = (wxWindow*)this ;
1360
1383
}
1361
1384
 
1362
1385
wxWindow * wxWindowBase::GetCapture()
1755
1778
        HIGetMousePosition(kHICoordSpaceWindow, window, &hiPoint);
1756
1779
        pt.h = hiPoint.x;
1757
1780
        pt.v = hiPoint.y;
1758
 
 #else 
 
1781
 #else
1759
1782
        CGrafPtr savePort ;
1760
1783
        Boolean swapped = QDSwapPort( GetWindowPort( window ) , &savePort ) ;
1761
1784
 
1784
1807
#if wxUSE_MENUS
1785
1808
bool wxWindowMac::DoPopupMenu(wxMenu *menu, int x, int y)
1786
1809
{
1787
 
    menu->SetInvokingWindow(this);
 
1810
#ifndef __WXUNIVERSAL__
 
1811
    menu->SetInvokingWindow((wxWindow*)this);
1788
1812
    menu->UpdateUI();
1789
1813
 
1790
1814
    if ( x == wxDefaultCoord && y == wxDefaultCoord )
1821
1845
    menu->SetInvokingWindow( NULL );
1822
1846
 
1823
1847
  return true;
 
1848
#else
 
1849
    // actually this shouldn't be called, because universal is having its own implementation
 
1850
    return false;
 
1851
#endif
1824
1852
}
1825
1853
#endif
1826
1854
 
1835
1863
    wxWindowBase::DoSetToolTip(tooltip);
1836
1864
 
1837
1865
    if ( m_tooltip )
1838
 
        m_tooltip->SetWindow(this);
 
1866
        m_tooltip->SetWindow((wxWindow*)this);
1839
1867
}
1840
1868
 
1841
1869
#endif
2119
2147
    if ( m_peer && m_peer->Ok() )
2120
2148
        m_peer->SetLabel( m_label ) ;
2121
2149
 
2122
 
    Refresh() ;
 
2150
    // do not trigger refreshes upon invisible and possible partly created objects
 
2151
    if ( MacIsReallyShown() )
 
2152
        Refresh() ;
2123
2153
}
2124
2154
 
2125
2155
wxString wxWindowMac::GetLabel() const
2247
2277
        return m_peer->IsVisible();
2248
2278
#endif
2249
2279
 
2250
 
    wxWindow* win = this ;
 
2280
    wxWindowMac* win = this ;
2251
2281
    while ( win->IsShown() )
2252
2282
    {
2253
2283
        if ( win->IsTopLevel() )
2280
2310
 
2281
2311
int wxWindowMac::GetCharHeight() const
2282
2312
{
2283
 
    wxClientDC dc( (wxWindowMac*)this ) ;
 
2313
    wxClientDC dc( (wxWindow*)this ) ;
2284
2314
 
2285
2315
    return dc.GetCharHeight() ;
2286
2316
}
2287
2317
 
2288
2318
int wxWindowMac::GetCharWidth() const
2289
2319
{
2290
 
    wxClientDC dc( (wxWindowMac*)this ) ;
 
2320
    wxClientDC dc( (wxWindow*)this ) ;
2291
2321
 
2292
2322
    return dc.GetCharWidth() ;
2293
2323
}
2299
2329
    if ( !fontToUse )
2300
2330
        fontToUse = &m_font;
2301
2331
 
2302
 
    wxClientDC dc( (wxWindowMac*) this ) ;
 
2332
    wxClientDC dc( (wxWindow*)this ) ;
2303
2333
    long lx,ly,ld,le ;
2304
2334
    dc.GetTextExtent( string , &lx , &ly , &ld, &le, (wxFont *)fontToUse ) ;
2305
2335
    if ( externalLeading )
2370
2400
    return m_frozenness != 0;
2371
2401
}
2372
2402
 
2373
 
wxWindowMac *wxGetActiveWindow()
 
2403
wxWindow *wxGetActiveWindow()
2374
2404
{
2375
2405
    // actually this is a windows-only concept
2376
2406
    return NULL;
2473
2503
// our own window origin is at leftOrigin/rightOrigin
2474
2504
//
2475
2505
 
 
2506
void  wxWindowMac::MacPaintGrowBox()
 
2507
{
 
2508
    if ( IsTopLevel() )
 
2509
        return ;
 
2510
 
 
2511
#if wxMAC_USE_CORE_GRAPHICS
 
2512
    if ( MacHasScrollBarCorner() )
 
2513
    {
 
2514
        Rect rect ;
 
2515
 
 
2516
        CGContextRef cgContext = (CGContextRef) MacGetCGContextRef() ;
 
2517
        wxASSERT( cgContext ) ;
 
2518
        
 
2519
        m_peer->GetRect( &rect ) ;
 
2520
 
 
2521
        int size = m_hScrollBar ? m_hScrollBar->GetSize().y : ( m_vScrollBar ? m_vScrollBar->GetSize().x : MAC_SCROLLBAR_SIZE ) ;
 
2522
        CGRect cgrect = CGRectMake( rect.right - size , rect.bottom - size , size , size ) ;
 
2523
        CGPoint cgpoint = CGPointMake( rect.right - size , rect.bottom - size ) ;
 
2524
        CGContextSaveGState( cgContext );
 
2525
        
 
2526
        wxMacCoreGraphicsColour bkgnd( m_macBackgroundBrush ) ;
 
2527
        bkgnd.Apply( cgContext );
 
2528
        CGContextFillRect( cgContext, cgrect );
 
2529
        CGContextRestoreGState( cgContext );
 
2530
    }
 
2531
#endif
 
2532
}
 
2533
 
 
2534
 
2476
2535
void wxWindowMac::MacPaintBorders( int leftOrigin , int rightOrigin )
2477
2536
{
2478
2537
    if ( IsTopLevel() )
2480
2539
 
2481
2540
    Rect rect ;
2482
2541
    bool hasFocus = m_peer->NeedsFocusRect() && m_peer->HasFocus() ;
2483
 
    bool hasBothScrollbars = (m_hScrollBar && m_hScrollBar->IsShown()) && (m_vScrollBar && m_vScrollBar->IsShown()) ;
2484
2542
 
2485
2543
    // back to the surrounding frame rectangle
2486
2544
    m_peer->GetRect( &rect ) ;
2487
2545
    InsetRect( &rect, -1 , -1 ) ;
2488
2546
 
2489
 
#if wxMAC_USE_CORE_GRAPHICS 
 
2547
#if wxMAC_USE_CORE_GRAPHICS
2490
2548
    {
2491
2549
        CGRect cgrect = CGRectMake( rect.left , rect.top , rect.right - rect.left ,
2492
2550
            rect.bottom - rect.top ) ;
2516
2574
        {
2517
2575
            HIThemeDrawFocusRect( &cgrect , true , cgContext , kHIThemeOrientationNormal ) ;
2518
2576
        }
2519
 
 
 
2577
#if 0 // TODO REMOVE now done in a separate call earlier in drawing the window itself
2520
2578
        m_peer->GetRect( &rect ) ;
2521
 
        if ( hasBothScrollbars )
 
2579
        if ( MacHasScrollBarCorner() )
2522
2580
        {
2523
 
            int size = m_hScrollBar->GetWindowVariant() == wxWINDOW_VARIANT_NORMAL ? 16 : 12 ;
 
2581
            int variant = (m_hScrollBar == NULL ? m_vScrollBar : m_hScrollBar ) ->GetWindowVariant();
 
2582
            int size = m_hScrollBar ? m_hScrollBar->GetSize().y : ( m_vScrollBar ? m_vScrollBar->GetSize().x : MAC_SCROLLBAR_SIZE ) ;
2524
2583
            CGRect cgrect = CGRectMake( rect.right - size , rect.bottom - size , size , size ) ;
2525
2584
            CGPoint cgpoint = CGPointMake( rect.right - size , rect.bottom - size ) ;
2526
2585
            HIThemeGrowBoxDrawInfo info ;
2528
2587
            info.version = 0 ;
2529
2588
            info.state = IsEnabled() ? kThemeStateActive : kThemeStateInactive ;
2530
2589
            info.kind = kHIThemeGrowBoxKindNone ;
 
2590
            // contrary to the docs ...SizeSmall does not work
2531
2591
            info.size = kHIThemeGrowBoxSizeNormal ;
2532
 
            info.direction = kThemeGrowRight | kThemeGrowDown ;
 
2592
            info.direction = 0 ;
2533
2593
            HIThemeDrawGrowBox( &cgpoint , &info , cgContext , kHIThemeOrientationNormal ) ;
2534
2594
        }
 
2595
#endif
2535
2596
    }
2536
2597
 #else
2537
2598
    {
2550
2611
 
2551
2612
        if ( hasFocus )
2552
2613
            DrawThemeFocusRect( &rect , true ) ;
2553
 
 
2554
 
        if ( hasBothScrollbars )
 
2614
   /*
 
2615
        if ( hasBothScrollbars ) // hasBothScrollbars is not declared
2555
2616
        {
2556
2617
            // GetThemeStandaloneGrowBoxBounds
2557
2618
            // DrawThemeStandaloneNoGrowBox
2558
2619
        }
 
2620
   */
2559
2621
    }
2560
2622
#endif
2561
2623
}
2581
2643
    {
2582
2644
        if ( m_hScrollBar )
2583
2645
        {
2584
 
            showScroller = ((range != 0) && (range > thumbVisible));
 
2646
            showScroller = HasFlag( wxALWAYS_SHOW_SB ) || ((range != 0) && (range > thumbVisible));
2585
2647
            if ( m_hScrollBar->IsShown() != showScroller )
2586
2648
            {
2587
2649
                m_hScrollBar->Show( showScroller );
2595
2657
    {
2596
2658
        if ( m_vScrollBar )
2597
2659
        {
2598
 
            showScroller = ((range != 0) && (range > thumbVisible));
 
2660
            showScroller = HasFlag( wxALWAYS_SHOW_SB ) || ((range != 0) && (range > thumbVisible));
2599
2661
            if ( m_vScrollBar->IsShown() != showScroller )
2600
2662
            {
2601
2663
                m_vScrollBar->Show( showScroller ) ;
2682
2744
        {
2683
2745
            wxRect rc( x, y, w, h );
2684
2746
            if (rect->Intersects( rc ))
2685
 
                child->SetSize( x + dx, y + dy, w, h );
 
2747
                child->SetSize( x + dx, y + dy, w, h, wxSIZE_AUTO|wxSIZE_ALLOW_MINUS_ONE );
2686
2748
        }
2687
2749
        else
2688
2750
        {
2689
 
            child->SetSize( x + dx, y + dy, w, h );
 
2751
            child->SetSize( x + dx, y + dy, w, h, wxSIZE_AUTO|wxSIZE_ALLOW_MINUS_ONE );
2690
2752
        }
2691
2753
    }
2692
2754
}
2722
2784
}
2723
2785
 
2724
2786
// Get the window with the focus
2725
 
wxWindowMac *wxWindowBase::DoFindFocus()
 
2787
wxWindow *wxWindowBase::DoFindFocus()
2726
2788
{
2727
2789
    ControlRef control ;
2728
2790
    GetKeyboardFocus( GetUserFocusWindow() , &control ) ;
2729
 
    return wxFindControlFromMacControl( control ) ;
 
2791
    return (wxWindow*)wxFindControlFromMacControl( control ) ;
2730
2792
}
2731
2793
 
2732
2794
void wxWindowMac::OnSetFocus( wxFocusEvent& event )
2751
2813
        Rect rect ;
2752
2814
 
2753
2815
        m_peer->GetRect( &rect ) ;
2754
 
        // auf den umgebenden Rahmen zurŸck
 
2816
        // auf den umgebenden Rahmen zurチᅡ゚ck
2755
2817
        InsetRect( &rect, -1 , -1 ) ;
2756
2818
 
2757
2819
        wxTopLevelWindowMac* top = MacGetTopLevelWindow();
2784
2846
{
2785
2847
    // This calls the UI-update mechanism (querying windows for
2786
2848
    // menu/toolbar/control state information)
2787
 
    if (wxUpdateUIEvent::CanUpdate(this))
 
2849
    if (wxUpdateUIEvent::CanUpdate(this) && IsShown())
2788
2850
        UpdateWindowUI(wxUPDATE_UI_FROMIDLE);
2789
2851
}
2790
2852
 
2857
2919
void wxWindowMac::Update()
2858
2920
{
2859
2921
#if TARGET_API_MAC_OSX
2860
 
    MacGetTopLevelWindow()->MacPerformUpdates() ;
 
2922
    wxTopLevelWindowMac* top = MacGetTopLevelWindow();
 
2923
    if (top)
 
2924
        top->MacPerformUpdates() ;
2861
2925
#else
2862
2926
    ::Draw1Control( m_peer->GetControlRef() ) ;
2863
2927
#endif
2943
3007
 
2944
3008
    int x , y ;
2945
3009
    wxSize size ;
2946
 
    const wxWindow* child = this ;
2947
 
    const wxWindow* parent = NULL ;
 
3010
    const wxWindowMac* child = this ;
 
3011
    const wxWindowMac* parent = NULL ;
2948
3012
 
2949
3013
    while ( !child->IsTopLevel() && ( parent = child->GetParent() ) != NULL )
2950
3014
    {
2951
 
        if ( parent->MacIsChildOfClientArea(child) )
 
3015
        if ( parent->MacIsChildOfClientArea((wxWindow*)child) )
2952
3016
        {
2953
3017
            size = parent->GetClientSize() ;
2954
3018
            wxPoint origin = parent->GetClientAreaOrigin() ;
3025
3089
            // for all the others only their client area, otherwise they
3026
3090
            // might be drawing with full alpha and eg put blue into
3027
3091
            // the grow-box area of a scrolled window (scroll sample)
3028
 
            wxDC* dc = new wxWindowDC(this);
 
3092
            wxDC* dc = new wxWindowDC((wxWindow*)this);
3029
3093
            if ( IsTopLevel() )
3030
3094
                dc->SetClippingRegion(wxRegion(updatergn));
3031
3095
            else
3037
3101
            delete dc ;
3038
3102
        }
3039
3103
 
 
3104
        MacPaintGrowBox();
 
3105
 
3040
3106
        // calculate a client-origin version of the update rgn and set m_updateRegion to that
3041
3107
        OffsetRgn( newupdate , -origin.x , -origin.y ) ;
3042
3108
        m_updateRegion = newupdate ;
3090
3156
                eventNc.SetEventObject( child );
3091
3157
                if ( !child->GetEventHandler()->ProcessEvent( eventNc ) )
3092
3158
                {
3093
 
#if wxMAC_USE_CORE_GRAPHICS 
 
3159
#if wxMAC_USE_CORE_GRAPHICS
3094
3160
                    child->MacPaintBorders(0, 0) ;
3095
3161
#else
3096
3162
                    {
3116
3182
    while ( iter )
3117
3183
    {
3118
3184
        if ( iter->IsTopLevel() )
3119
 
            return ((wxTopLevelWindow*)iter)->MacGetWindowRef() ;
3120
 
 
 
3185
        {
 
3186
            wxTopLevelWindow* toplevel = wxDynamicCast(iter,wxTopLevelWindow);
 
3187
            if ( toplevel )
 
3188
                return toplevel->MacGetWindowRef();
 
3189
#if wxUSE_POPUPWIN
 
3190
            wxPopupWindow* popupwin = wxDynamicCast(iter,wxPopupWindow);
 
3191
            if ( popupwin )
 
3192
                return popupwin->MacGetPopupWindowRef();
 
3193
#endif
 
3194
        }
3121
3195
        iter = iter->GetParent() ;
3122
3196
    }
3123
3197
 
3124
3198
    return NULL ;
3125
3199
}
3126
3200
 
 
3201
bool wxWindowMac::MacHasScrollBarCorner() const
 
3202
{
 
3203
    /* Returns whether the scroll bars in a wxScrolledWindow should be
 
3204
     * shortened. Scroll bars should be shortened if either:
 
3205
     *
 
3206
     * - both scroll bars are visible, or
 
3207
     *
 
3208
     * - there is a resize box in the parent frame's corner and this
 
3209
     *   window shares the bottom and right edge with the parent
 
3210
     *   frame.
 
3211
     */
 
3212
 
 
3213
    if ( m_hScrollBar == NULL && m_vScrollBar == NULL )
 
3214
        return false;
 
3215
 
 
3216
    if ( ( m_hScrollBar && m_hScrollBar->IsShown() )
 
3217
         && ( m_vScrollBar && m_vScrollBar->IsShown() ) )
 
3218
    {
 
3219
        // Both scroll bars visible
 
3220
        return true;
 
3221
    }
 
3222
    else
 
3223
    {
 
3224
        wxPoint thisWindowBottomRight = GetScreenRect().GetBottomRight();
 
3225
 
 
3226
        for ( const wxWindow *win = this; win; win = win->GetParent() )
 
3227
        {
 
3228
            const wxFrame *frame = wxDynamicCast( win, wxFrame ) ;
 
3229
            if ( frame )
 
3230
            {
 
3231
                if ( frame->GetWindowStyleFlag() & wxRESIZE_BORDER )
 
3232
                {
 
3233
                    // Parent frame has resize handle
 
3234
                    wxPoint frameBottomRight = frame->GetScreenRect().GetBottomRight();
 
3235
 
 
3236
                    // Note: allow for some wiggle room here as wxMac's
 
3237
                    // window rect calculations seem to be imprecise
 
3238
                    if ( abs( thisWindowBottomRight.x - frameBottomRight.x ) <= 2
 
3239
                        && abs( thisWindowBottomRight.y - frameBottomRight.y ) <= 2 )
 
3240
                    {
 
3241
                        // Parent frame has resize handle and shares
 
3242
                        // right bottom corner
 
3243
                        return true ;
 
3244
                    }
 
3245
                    else
 
3246
                    {
 
3247
                        // Parent frame has resize handle but doesn't
 
3248
                        // share right bottom corner
 
3249
                        return false ;
 
3250
                    }
 
3251
                }
 
3252
                else
 
3253
                {
 
3254
                    // Parent frame doesn't have resize handle
 
3255
                    return false ;
 
3256
                }
 
3257
            }
 
3258
        }
 
3259
 
 
3260
        // No parent frame found
 
3261
        return false ;
 
3262
    }
 
3263
}
 
3264
 
3127
3265
void wxWindowMac::MacCreateScrollBars( long style )
3128
3266
{
3129
3267
    wxASSERT_MSG( m_vScrollBar == NULL && m_hScrollBar == NULL , wxT("attempt to create window twice") ) ;
3130
3268
 
3131
3269
    if ( style & ( wxVSCROLL | wxHSCROLL ) )
3132
3270
    {
3133
 
        bool hasBoth = ( style & wxVSCROLL ) && ( style & wxHSCROLL ) ;
3134
3271
        int scrlsize = MAC_SCROLLBAR_SIZE ;
3135
3272
        if ( GetWindowVariant() == wxWINDOW_VARIANT_SMALL || GetWindowVariant() == wxWINDOW_VARIANT_MINI )
3136
3273
        {
3137
3274
            scrlsize = MAC_SMALL_SCROLLBAR_SIZE ;
3138
3275
        }
3139
3276
 
3140
 
        int adjust = hasBoth ? scrlsize - 1: 0 ;
 
3277
        int adjust = MacHasScrollBarCorner() ? scrlsize - 1: 0 ;
3141
3278
        int width, height ;
3142
3279
        GetClientSize( &width , &height ) ;
3143
3280
 
3146
3283
        wxPoint hPoint(0, height - scrlsize) ;
3147
3284
        wxSize hSize(width - adjust, scrlsize) ;
3148
3285
 
 
3286
        // we have to set the min size to a smaller value, otherwise they cannot get smaller (InitialSize sets MinSize)
3149
3287
        if ( style & wxVSCROLL )
3150
 
            m_vScrollBar = new wxScrollBar(this, wxID_ANY, vPoint, vSize , wxVERTICAL);
 
3288
        {
 
3289
            m_vScrollBar = new wxScrollBar((wxWindow*)this, wxID_ANY, vPoint, vSize , wxVERTICAL);
 
3290
            m_vScrollBar->SetMinSize( wxDefaultSize );
 
3291
        }
3151
3292
 
3152
 
        if ( style  & wxHSCROLL )
3153
 
            m_hScrollBar = new wxScrollBar(this, wxID_ANY, hPoint, hSize , wxHORIZONTAL);
 
3293
        if ( style & wxHSCROLL )
 
3294
        {
 
3295
            m_hScrollBar = new wxScrollBar((wxWindow*)this, wxID_ANY, hPoint, hSize , wxHORIZONTAL);
 
3296
            m_hScrollBar->SetMinSize( wxDefaultSize );
 
3297
        }
3154
3298
    }
3155
3299
 
3156
3300
    // because the create does not take into account the client area origin
3170
3314
    if ( !m_hScrollBar && !m_vScrollBar )
3171
3315
        return ;
3172
3316
 
3173
 
    bool hasBoth = (m_hScrollBar && m_hScrollBar->IsShown()) && ( m_vScrollBar && m_vScrollBar->IsShown()) ;
3174
3317
    int scrlsize = m_hScrollBar ? m_hScrollBar->GetSize().y : ( m_vScrollBar ? m_vScrollBar->GetSize().x : MAC_SCROLLBAR_SIZE ) ;
3175
 
    int adjust = hasBoth ? scrlsize - 1 : 0 ;
 
3318
    int adjust = MacHasScrollBarCorner() ? scrlsize - 1 : 0 ;
3176
3319
 
3177
3320
    // get real client area
3178
3321
    int width, height ;
3321
3464
 
3322
3465
// Find the wxWindowMac at the current mouse position, returning the mouse
3323
3466
// position.
3324
 
wxWindowMac * wxFindWindowAtPointer( wxPoint& pt )
 
3467
wxWindow * wxFindWindowAtPointer( wxPoint& pt )
3325
3468
{
3326
3469
    pt = wxGetMousePosition();
3327
3470
    wxWindowMac* found = wxFindWindowAtPoint(pt);
3328
3471
 
3329
 
    return found;
 
3472
    return (wxWindow*) found;
3330
3473
}
3331
3474
 
3332
3475
// Get the current mouse position.
3376
3519
{
3377
3520
}
3378
3521
 
3379
 
Rect wxMacGetBoundsForControl( wxWindow* window , const wxPoint& pos , const wxSize &size , bool adjustForOrigin )
 
3522
Rect wxMacGetBoundsForControl( wxWindowMac* window , const wxPoint& pos , const wxSize &size , bool adjustForOrigin )
3380
3523
{
3381
3524
    int x, y, w, h ;
3382
3525
 
3431
3574
#endif
3432
3575
}
3433
3576
 
3434
 
wxByte wxWindowMac::GetTransparent() const 
 
3577
wxByte wxWindowMac::GetTransparent() const
3435
3578
{
3436
3579
    return m_macAlpha ;
3437
3580
}