~zulcss/ubuntu/lucid/likewise-open/likewise-open-sru

« back to all changes in this revision

Viewing changes to domainjoin/domainjoin-gui/carbon/DomainJoin/HIFramework/TWindow.cp

  • Committer: Bazaar Package Importer
  • Author(s): Rick Clark
  • Date: 2008-08-27 08:56:20 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20080827085620-5q0f58b9qtog9myq
Tags: 4.1.0.2956-0ubuntu1
* missing-likewise-logo.diff: removed
* fixed copyright notice
* updated Standards-Version to 3.8.0
* removed path from command in prerm
* removed stop in S runlevel

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
    File:               TWindow.cp
 
3
 
 
4
    Version:    Mac OS X
 
5
 
 
6
        Disclaimer:     IMPORTANT:  This Apple software is supplied to you by Apple Computer, Inc.
 
7
                                ("Apple") in consideration of your agreement to the following terms, and your
 
8
                                use, installation, modification or redistribution of this Apple software
 
9
                                constitutes acceptance of these terms.  If you do not agree with these terms,
 
10
                                please do not use, install, modify or redistribute this Apple software.
 
11
 
 
12
                                In consideration of your agreement to abide by the following terms, and subject
 
13
                                to these terms, Apple grants you a personal, non-exclusive license, under Apple�s
 
14
                                copyrights in this original Apple software (the "Apple Software"), to use,
 
15
                                reproduce, modify and redistribute the Apple Software, with or without
 
16
                                modifications, in source and/or binary forms; provided that if you redistribute
 
17
                                the Apple Software in its entirety and without modifications, you must retain
 
18
                                this notice and the following text and disclaimers in all such redistributions of
 
19
                                the Apple Software.  Neither the name, trademarks, service marks or logos of
 
20
                                Apple Computer, Inc. may be used to endorse or promote products derived from the
 
21
                                Apple Software without specific prior written permission from Apple.  Except as
 
22
                                expressly stated in this notice, no other rights or licenses, express or implied,
 
23
                                are granted by Apple herein, including but not limited to any patent rights that
 
24
                                may be infringed by your derivative works or by other works in which the Apple
 
25
                                Software may be incorporated.
 
26
 
 
27
                                The Apple Software is provided by Apple on an "AS IS" basis.  APPLE MAKES NO
 
28
                                WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED
 
29
                                WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 
30
                                PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND OPERATION ALONE OR IN
 
31
                                COMBINATION WITH YOUR PRODUCTS.
 
32
 
 
33
                                IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR
 
34
                                CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
 
35
                                GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 
36
                                ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, MODIFICATION AND/OR DISTRIBUTION
 
37
                                OF THE APPLE SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF CONTRACT, TORT
 
38
                                (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN
 
39
                                ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
40
 
 
41
        Copyright � 2000-2005 Apple Computer, Inc., All Rights Reserved
 
42
*/
 
43
 
 
44
#include "TWindow.h"
 
45
#include "TNib.h"
 
46
 
 
47
// -----------------------------------------------------------------------------
 
48
//      constants
 
49
// -----------------------------------------------------------------------------
 
50
//
 
51
 
 
52
// Our base class for creating a Mac OS window which can be Carbon Event-savvy.
 
53
 
 
54
// -----------------------------------------------------------------------------
 
55
//      TWindow private constructor
 
56
// -----------------------------------------------------------------------------
 
57
//
 
58
TWindow::TWindow(
 
59
    int                 inAppSignature,
 
60
        CFStringRef                     inName,
 
61
        CFStringRef                     inNibName )
 
62
        : _appSignature(inAppSignature)
 
63
{
 
64
        fWindow = NULL;
 
65
 
 
66
        Init( inName, inNibName );
 
67
}
 
68
 
 
69
// -----------------------------------------------------------------------------
 
70
//      TWindow private constructor
 
71
// -----------------------------------------------------------------------------
 
72
//
 
73
TWindow::TWindow(
 
74
    int                 inAppSignature,
 
75
        WindowRef                       inWindow )
 
76
        : _appSignature(inAppSignature)
 
77
{
 
78
        fWindow = NULL;
 
79
}
 
80
 
 
81
// -----------------------------------------------------------------------------
 
82
//      TWindow destructor
 
83
// -----------------------------------------------------------------------------
 
84
//
 
85
TWindow::~TWindow()
 
86
{
 
87
        if ( fWindow != NULL )
 
88
                DisposeWindow( fWindow );
 
89
}
 
90
 
 
91
// -----------------------------------------------------------------------------
 
92
//      Init (with WindowRef)
 
93
// -----------------------------------------------------------------------------
 
94
//
 
95
OSStatus
 
96
TWindow::Init(
 
97
        WindowRef                       inWindow )
 
98
{
 
99
        OSStatus                        err;
 
100
        static const
 
101
        EventTypeSpec           kEvents[] =
 
102
                                                        {
 
103
                                                                { kEventClassWindow, kEventWindowClose },
 
104
                                                                { kEventClassWindow, kEventWindowActivated },
 
105
                                                                { kEventClassWindow, kEventWindowDeactivated },
 
106
                                                                { kEventClassWindow, kEventWindowDispose },
 
107
                                                                { kEventClassWindow, kEventWindowDrawContent },
 
108
                                                                { kEventClassWindow, kEventWindowBoundsChanged },
 
109
                                                                { kEventClassWindow, kEventWindowGetIdealSize },
 
110
                                                                { kEventClassWindow, kEventWindowGetMinimumSize },
 
111
                                                                { kEventClassWindow, kEventWindowGetMaximumSize },
 
112
                                                                { kEventClassCommand, kEventCommandProcess },
 
113
                                                                { kEventClassCommand, kEventCommandUpdateStatus },
 
114
                                                        };
 
115
        TWindow*                        tWindow;
 
116
 
 
117
        require_action( inWindow != NULL, InvalidWindow, err = paramErr );
 
118
 
 
119
        fWindow = inWindow;
 
120
 
 
121
        err = RegisterForEvents( GetEventTypeCount( kEvents ), kEvents );
 
122
        require_noerr( err, CantRegisterForEvents );
 
123
        
 
124
        tWindow = this;
 
125
        err = SetWindowProperty( inWindow, 'hifr', 'twin', sizeof( TWindow* ), &tWindow );
 
126
 
 
127
CantRegisterForEvents:
 
128
InvalidWindow:
 
129
        return err;
 
130
}
 
131
 
 
132
// -----------------------------------------------------------------------------
 
133
//      Init (from Nib)
 
134
// -----------------------------------------------------------------------------
 
135
//
 
136
OSStatus
 
137
TWindow::Init(
 
138
        CFStringRef                     inWindowName,
 
139
        CFStringRef                     inNibName )
 
140
{
 
141
        OSStatus                        err;
 
142
        TNib                            nib;
 
143
        WindowRef                       window;
 
144
 
 
145
        err = nib.Init( inNibName );
 
146
        require_noerr( err, CantInitNib );
 
147
 
 
148
        err = nib.CreateWindow( inWindowName, &window );
 
149
        require_noerr( err, CantCreateWindow );
 
150
 
 
151
        err = Init( window );
 
152
 
 
153
CantCreateWindow:
 
154
CantInitNib:
 
155
        return err;
 
156
}
 
157
 
 
158
// -----------------------------------------------------------------------------
 
159
//      Init
 
160
// -----------------------------------------------------------------------------
 
161
//
 
162
OSStatus
 
163
TWindow::Init(
 
164
        WindowClass                     inClass,
 
165
        WindowAttributes        inAttributes,
 
166
        const Rect&                     inBounds )
 
167
{
 
168
        OSStatus                        err;
 
169
        WindowRef                       window;
 
170
 
 
171
        err = CreateNewWindow( inClass, inAttributes, &inBounds, &window );
 
172
        require_noerr( err, CantCreateWindow );
 
173
 
 
174
        err = Init( window );
 
175
 
 
176
CantCreateWindow:
 
177
        return err;
 
178
}
 
179
 
 
180
// -----------------------------------------------------------------------------
 
181
//      GetEventTarget
 
182
// -----------------------------------------------------------------------------
 
183
//
 
184
EventTargetRef
 
185
TWindow::GetEventTarget()
 
186
{
 
187
        return GetWindowEventTarget( GetWindowRef() );
 
188
}
 
189
 
 
190
// -----------------------------------------------------------------------------
 
191
//      SourceWindowDispose
 
192
// -----------------------------------------------------------------------------
 
193
//
 
194
void
 
195
TWindow::SourceWindowDispose()
 
196
{
 
197
        fWindow = NULL;
 
198
}
 
199
 
 
200
// -----------------------------------------------------------------------------
 
201
//      Close
 
202
// -----------------------------------------------------------------------------
 
203
//
 
204
void
 
205
TWindow::Close()
 
206
{
 
207
        Hide();
 
208
        //delete this;
 
209
}
 
210
 
 
211
// -----------------------------------------------------------------------------
 
212
//      GetPort
 
213
// -----------------------------------------------------------------------------
 
214
//
 
215
CGrafPtr
 
216
TWindow::GetPort() const
 
217
{
 
218
        return GetWindowPort( GetWindowRef() );
 
219
}
 
220
 
 
221
// -----------------------------------------------------------------------------
 
222
//      SetTitle
 
223
// -----------------------------------------------------------------------------
 
224
//
 
225
void
 
226
TWindow::SetTitle(
 
227
        CFStringRef                     inTitle )
 
228
{
 
229
        SetWindowTitleWithCFString( GetWindowRef(), inTitle );
 
230
}
 
231
 
 
232
// -----------------------------------------------------------------------------
 
233
//      CopyTitle
 
234
// -----------------------------------------------------------------------------
 
235
//
 
236
CFStringRef
 
237
TWindow::CopyTitle() const
 
238
{
 
239
        CFStringRef                     outTitle;
 
240
 
 
241
        CopyWindowTitleAsCFString( GetWindowRef(), &outTitle );
 
242
 
 
243
        return outTitle;
 
244
}
 
245
 
 
246
// -----------------------------------------------------------------------------
 
247
//      SetAlternateTitle
 
248
// -----------------------------------------------------------------------------
 
249
//
 
250
void
 
251
TWindow::SetAlternateTitle(
 
252
        CFStringRef                     inTitle )
 
253
{
 
254
        SetWindowAlternateTitle( GetWindowRef(), inTitle );
 
255
}
 
256
 
 
257
// -----------------------------------------------------------------------------
 
258
//      CopyAlternateTitle
 
259
// -----------------------------------------------------------------------------
 
260
//
 
261
CFStringRef
 
262
TWindow::CopyAlternateTitle() const
 
263
{
 
264
        CFStringRef     outTitle;
 
265
 
 
266
        CopyWindowAlternateTitle( GetWindowRef(), &outTitle );
 
267
 
 
268
        return outTitle;
 
269
}
 
270
 
 
271
// -----------------------------------------------------------------------------
 
272
//      Show
 
273
// -----------------------------------------------------------------------------
 
274
//
 
275
void
 
276
TWindow::Show()
 
277
{
 
278
        ShowWindow( GetWindowRef() );
 
279
 
 
280
        if ( GetWindowRef() == ActiveNonFloatingWindow() )
 
281
        {
 
282
                WindowActivationScope           scope;
 
283
 
 
284
                GetWindowActivationScope( GetWindowRef(), &scope );
 
285
                if ( scope == kWindowActivationScopeAll )
 
286
                        AdvanceKeyboardFocus( GetWindowRef() );
 
287
        }
 
288
}
 
289
 
 
290
// -----------------------------------------------------------------------------
 
291
//      Hide
 
292
// -----------------------------------------------------------------------------
 
293
//
 
294
void
 
295
TWindow::Hide()
 
296
{
 
297
        HideWindow( GetWindowRef() );
 
298
}
 
299
 
 
300
// -----------------------------------------------------------------------------
 
301
//      IsVisible
 
302
// -----------------------------------------------------------------------------
 
303
//
 
304
bool
 
305
TWindow::IsVisible() const
 
306
{
 
307
        return IsWindowVisible( GetWindowRef() );
 
308
}
 
309
 
 
310
// -----------------------------------------------------------------------------
 
311
//      Select
 
312
// -----------------------------------------------------------------------------
 
313
//
 
314
void
 
315
TWindow::Select()
 
316
{
 
317
        SelectWindow( GetWindowRef() );
 
318
}
 
319
 
 
320
// -----------------------------------------------------------------------------
 
321
//      Draw
 
322
// -----------------------------------------------------------------------------
 
323
//
 
324
void
 
325
TWindow::Draw()
 
326
{
 
327
}
 
328
 
 
329
// -----------------------------------------------------------------------------
 
330
//      Activated
 
331
// -----------------------------------------------------------------------------
 
332
//
 
333
void
 
334
TWindow::Activated()
 
335
{
 
336
}
 
337
 
 
338
// -----------------------------------------------------------------------------
 
339
//      Deactivated
 
340
// -----------------------------------------------------------------------------
 
341
//
 
342
void
 
343
TWindow::Deactivated()
 
344
{
 
345
}
 
346
 
 
347
// -----------------------------------------------------------------------------
 
348
//      Moved
 
349
// -----------------------------------------------------------------------------
 
350
//
 
351
void
 
352
TWindow::Moved()
 
353
{
 
354
}
 
355
 
 
356
// -----------------------------------------------------------------------------
 
357
//      Resized
 
358
// -----------------------------------------------------------------------------
 
359
//
 
360
void
 
361
TWindow::Resized()
 
362
{
 
363
}
 
364
 
 
365
// -----------------------------------------------------------------------------
 
366
//      GetIdealSize
 
367
// -----------------------------------------------------------------------------
 
368
//
 
369
Point
 
370
TWindow::GetIdealSize()
 
371
{
 
372
        Point idealSize = { 0, 0 };
 
373
 
 
374
        return idealSize;
 
375
}
 
376
 
 
377
// -----------------------------------------------------------------------------
 
378
//      GetMinimumSize
 
379
// -----------------------------------------------------------------------------
 
380
//
 
381
Point
 
382
TWindow::GetMinimumSize()
 
383
{
 
384
        Point minSize = { 0, 0 };
 
385
 
 
386
        return minSize;
 
387
}
 
388
 
 
389
// -----------------------------------------------------------------------------
 
390
//      GetMaximumSize
 
391
// -----------------------------------------------------------------------------
 
392
//
 
393
Point
 
394
TWindow::GetMaximumSize()
 
395
{
 
396
        Point maxSize = { 0, 0 };
 
397
 
 
398
        return maxSize;
 
399
}
 
400
 
 
401
// -----------------------------------------------------------------------------
 
402
//      SetBounds
 
403
// -----------------------------------------------------------------------------
 
404
//
 
405
void
 
406
TWindow::SetBounds(
 
407
        const Rect&                     inBounds )
 
408
{
 
409
        SetWindowBounds( GetWindowRef(), kWindowStructureRgn, &inBounds );
 
410
}
 
411
 
 
412
// -----------------------------------------------------------------------------
 
413
//      InvalidateArea
 
414
// -----------------------------------------------------------------------------
 
415
//
 
416
void
 
417
TWindow::InvalidateArea(
 
418
        RgnHandle                       inRegion )
 
419
{
 
420
        InvalWindowRgn( GetWindowRef(), inRegion );
 
421
}
 
422
 
 
423
// -----------------------------------------------------------------------------
 
424
//      InvalidateArea
 
425
// -----------------------------------------------------------------------------
 
426
//
 
427
void
 
428
TWindow::InvalidateArea(
 
429
        const Rect&                     inRect )
 
430
{
 
431
        InvalWindowRect( GetWindowRef(), &inRect );
 
432
}
 
433
 
 
434
// -----------------------------------------------------------------------------
 
435
//      ValidateArea
 
436
// -----------------------------------------------------------------------------
 
437
//
 
438
void
 
439
TWindow::ValidateArea(
 
440
        RgnHandle                       inRegion )
 
441
{
 
442
        ValidWindowRgn( GetWindowRef(), inRegion );
 
443
}
 
444
 
 
445
// -----------------------------------------------------------------------------
 
446
//      ValidateArea
 
447
// -----------------------------------------------------------------------------
 
448
//
 
449
void
 
450
TWindow::ValidateArea(
 
451
        const Rect&                     inRect )
 
452
{
 
453
        ValidWindowRect( GetWindowRef(), &inRect );
 
454
}
 
455
 
 
456
// -----------------------------------------------------------------------------
 
457
//      UpdateCommandStatus
 
458
// -----------------------------------------------------------------------------
 
459
//
 
460
Boolean
 
461
TWindow::UpdateCommandStatus(
 
462
        const HICommandExtended&        inCommand )
 
463
{
 
464
        if ( inCommand.commandID == kHICommandClose )
 
465
        {
 
466
                EnableMenuCommand( NULL, inCommand.commandID );
 
467
                return true;
 
468
        }
 
469
 
 
470
        return false; // not handled
 
471
}
 
472
 
 
473
// -----------------------------------------------------------------------------
 
474
//      HandleCommand
 
475
// -----------------------------------------------------------------------------
 
476
//
 
477
Boolean
 
478
TWindow::HandleCommand(
 
479
        const HICommandExtended&                inCommand )
 
480
{
 
481
        return false; // not handled
 
482
}
 
483
 
 
484
// -----------------------------------------------------------------------------
 
485
//      SetDefaultButton
 
486
// -----------------------------------------------------------------------------
 
487
//
 
488
void
 
489
TWindow::SetDefaultButton(
 
490
        HIViewRef                       inView )
 
491
{
 
492
        SetWindowDefaultButton( GetWindowRef(), inView );
 
493
}
 
494
 
 
495
// -----------------------------------------------------------------------------
 
496
//      SetCancelButton
 
497
// -----------------------------------------------------------------------------
 
498
//
 
499
void
 
500
TWindow::SetCancelButton(
 
501
        HIViewRef                       inView )
 
502
{
 
503
        SetWindowCancelButton( GetWindowRef(), inView );
 
504
}
 
505
 
 
506
// -----------------------------------------------------------------------------
 
507
//      HandleEvent
 
508
// -----------------------------------------------------------------------------
 
509
//
 
510
OSStatus
 
511
TWindow::HandleEvent(
 
512
        EventHandlerCallRef             inRef,
 
513
        TCarbonEvent&                   inEvent )
 
514
{
 
515
        OSStatus                                result = eventNotHandledErr;
 
516
        UInt32                                  attributes;
 
517
        HICommandExtended               command;
 
518
 
 
519
        switch ( inEvent.GetClass() )
 
520
        {
 
521
                case kEventClassCommand:
 
522
                        {
 
523
                                inEvent.GetParameter( kEventParamDirectObject, &command );
 
524
 
 
525
                                switch ( inEvent.GetKind() )
 
526
                                {
 
527
                                        case kEventCommandProcess:
 
528
                                                if ( this->HandleCommand( command ) )
 
529
                                                        result = noErr;
 
530
                                                break;
 
531
 
 
532
                                        case kEventCommandUpdateStatus:
 
533
                                                if ( this->UpdateCommandStatus( command ) )
 
534
                                                        result = noErr;
 
535
                                                break;
 
536
                                }
 
537
                        }
 
538
                        break;
 
539
 
 
540
                case kEventClassWindow:
 
541
                        switch ( inEvent.GetKind() )
 
542
                        {
 
543
                                case kEventWindowActivated:
 
544
                                        CallNextEventHandler( inRef, inEvent.GetEventRef() );
 
545
                                        this->Activated();
 
546
                                        result = noErr;
 
547
                                        break;
 
548
 
 
549
                                case kEventWindowBoundsChanged:
 
550
                                        if ( inEvent.GetParameter( kEventParamAttributes, &attributes ) )
 
551
                                        {
 
552
                                                if ( attributes & kWindowBoundsChangeSizeChanged )
 
553
                                                {
 
554
                                                        this->Resized();
 
555
                                                        result = noErr;
 
556
                                                }
 
557
                                                else if ( attributes & kWindowBoundsChangeOriginChanged )
 
558
                                                {
 
559
                                                        this->Moved();
 
560
                                                        result = noErr;
 
561
                                                }
 
562
                                        }
 
563
                                        break;
 
564
 
 
565
                                case kEventWindowClose:
 
566
                                        this->Close();
 
567
                                        result = noErr;
 
568
                                        break;
 
569
 
 
570
                                case kEventWindowDeactivated:
 
571
                                        CallNextEventHandler( inRef, inEvent.GetEventRef() );
 
572
                                        this->Deactivated();
 
573
                                        result = noErr;
 
574
                                        break;
 
575
 
 
576
                                case kEventWindowDispose:
 
577
                                        CallNextEventHandler( inRef, inEvent.GetEventRef() );
 
578
                                        this->SourceWindowDispose();
 
579
                                        result = noErr;
 
580
                                        break;
 
581
 
 
582
                                case kEventWindowDrawContent:
 
583
                                        CallNextEventHandler( inRef, inEvent.GetEventRef() );
 
584
                                        this->Draw();
 
585
                                        result = noErr;
 
586
                                        break;
 
587
 
 
588
                                case kEventWindowGetIdealSize:
 
589
                                        {
 
590
                                                Point   size = this->GetIdealSize();
 
591
 
 
592
                                                if ( (size.h != 0) && (size.v != 0) )
 
593
                                                {
 
594
                                                        inEvent.SetParameter( kEventParamDimensions, size );
 
595
                                                        result = noErr;
 
596
                                                }
 
597
                                        }
 
598
                                        break;
 
599
 
 
600
                                case kEventWindowGetMinimumSize:
 
601
                                        {
 
602
                                                Point   size = this->GetMinimumSize();
 
603
 
 
604
                                                if ( (size.h != 0) && (size.v != 0) )
 
605
                                                {
 
606
                                                        inEvent.SetParameter( kEventParamDimensions, size );
 
607
                                                        result = noErr;
 
608
                                                }
 
609
                                        }
 
610
                                        break;
 
611
 
 
612
                                case kEventWindowGetMaximumSize:
 
613
                                        {
 
614
                                                Point   size = this->GetIdealSize();
 
615
 
 
616
                                                if ( (size.h != 0) && (size.v != 0) )
 
617
                                                {
 
618
                                                        inEvent.SetParameter( kEventParamDimensions, size );
 
619
                                                        result = noErr;
 
620
                                                }
 
621
                                        }
 
622
                                        break;
 
623
                        }
 
624
        };
 
625
 
 
626
        return result;
 
627
}
 
628
 
 
629
// -----------------------------------------------------------------------------
 
630
//      GetView
 
631
// -----------------------------------------------------------------------------
 
632
//
 
633
HIViewRef
 
634
TWindow::GetView(
 
635
        ControlID                               inID )
 
636
{
 
637
        HIViewRef                               view;
 
638
 
 
639
        if ( GetControlByID( GetWindowRef(), &inID, &view ) != noErr )
 
640
                view = NULL;
 
641
 
 
642
        return view;
 
643
}
 
644
 
 
645
// -----------------------------------------------------------------------------
 
646
//      GetView
 
647
// -----------------------------------------------------------------------------
 
648
//
 
649
HIViewRef
 
650
TWindow::GetView(
 
651
        OSType                                  inSignature,
 
652
        SInt32                                  inID  )
 
653
{
 
654
        HIViewRef                               view;
 
655
        ControlID                               viewID = { inSignature, inID };
 
656
 
 
657
        view = GetView( viewID );
 
658
 
 
659
        return view;
 
660
}
 
661
 
 
662
// -----------------------------------------------------------------------------
 
663
//      EnableView
 
664
// -----------------------------------------------------------------------------
 
665
//
 
666
OSStatus
 
667
TWindow::EnableView(
 
668
        ControlID                               inID )
 
669
{
 
670
        OSStatus                                err = noErr;
 
671
        HIViewRef                               view;
 
672
 
 
673
        view = GetView( inID );
 
674
        require_action( view != NULL, CantGetView, err = errUnknownControl );
 
675
 
 
676
        EnableControl( view );
 
677
 
 
678
CantGetView:
 
679
        return err;
 
680
}
 
681
 
 
682
// -----------------------------------------------------------------------------
 
683
//      EnableView
 
684
// -----------------------------------------------------------------------------
 
685
//
 
686
OSStatus
 
687
TWindow::EnableView(
 
688
        OSType                                  inSignature,
 
689
        SInt32                                  inID  )
 
690
{
 
691
        OSStatus                                err;
 
692
        ControlID                               viewID = { inSignature, inID };
 
693
 
 
694
        err = EnableView( viewID );
 
695
 
 
696
        return err;
 
697
}
 
698
 
 
699
// -----------------------------------------------------------------------------
 
700
//      DisableView
 
701
// -----------------------------------------------------------------------------
 
702
//
 
703
OSStatus
 
704
TWindow::DisableView(
 
705
        ControlID                               inID )
 
706
{
 
707
        OSStatus                                err = noErr;
 
708
        HIViewRef                               view;
 
709
 
 
710
        view = GetView( inID );
 
711
        require_action( view != NULL, CantGetView, err = errUnknownControl );
 
712
 
 
713
        DisableControl( view );
 
714
 
 
715
CantGetView:
 
716
        return err;
 
717
}
 
718
 
 
719
// -----------------------------------------------------------------------------
 
720
//      DisableView
 
721
// -----------------------------------------------------------------------------
 
722
//
 
723
OSStatus
 
724
TWindow::DisableView(
 
725
        OSType                                  inSignature,
 
726
        SInt32                                  inID  )
 
727
{
 
728
        OSStatus                                err;
 
729
        ControlID                               viewID = { inSignature, inID };
 
730
 
 
731
        err = DisableView( viewID );
 
732
 
 
733
        return err;
 
734
}
 
735
 
 
736
// -----------------------------------------------------------------------------
 
737
//      ShowView
 
738
// -----------------------------------------------------------------------------
 
739
//
 
740
OSStatus
 
741
TWindow::ShowView(
 
742
        ControlID                               inID )
 
743
{
 
744
        OSStatus                                err;
 
745
        HIViewRef                               view;
 
746
 
 
747
        view = GetView( inID );
 
748
        require_action( view != NULL, CantGetView, err = errUnknownControl );
 
749
 
 
750
        ShowControl( view );
 
751
 
 
752
CantGetView:
 
753
        return err;
 
754
}
 
755
 
 
756
// -----------------------------------------------------------------------------
 
757
//      ShowView
 
758
// -----------------------------------------------------------------------------
 
759
//
 
760
OSStatus
 
761
TWindow::ShowView(
 
762
        OSType                                  inSignature,
 
763
        SInt32                                  inID  )
 
764
{
 
765
        OSStatus                                err;
 
766
        ControlID                               viewID = { inSignature, inID };
 
767
 
 
768
        err = ShowView( viewID );
 
769
 
 
770
        return err;
 
771
}
 
772
 
 
773
// -----------------------------------------------------------------------------
 
774
//      HideView
 
775
// -----------------------------------------------------------------------------
 
776
//
 
777
OSStatus
 
778
TWindow::HideView(
 
779
        ControlID                               inID )
 
780
{
 
781
        HIViewRef                               view;
 
782
        OSStatus                                err;
 
783
 
 
784
        view = GetView( inID );
 
785
        require_action( view != NULL, CantGetView, err = errUnknownControl );
 
786
 
 
787
        HideControl( view );
 
788
 
 
789
CantGetView:
 
790
        return err;
 
791
}
 
792
 
 
793
// -----------------------------------------------------------------------------
 
794
//      HideView
 
795
// -----------------------------------------------------------------------------
 
796
//
 
797
OSStatus
 
798
TWindow::HideView(
 
799
        OSType                                  inSignature,
 
800
        SInt32                                  inID  )
 
801
{
 
802
        OSStatus                                err;
 
803
        ControlID                               viewID = { inSignature, inID };
 
804
 
 
805
        err = HideView( viewID );
 
806
 
 
807
        return err;
 
808
}
 
809
 
 
810
// --------------------------------------------------------------------------------
 
811
//      GetTWindowFromWindowRef
 
812
// --------------------------------------------------------------------------------
 
813
//
 
814
TWindow*
 
815
TWindow::GetTWindowFromWindowRef(
 
816
        WindowRef                               inWindowRef )
 
817
{
 
818
        TWindow*                                tWindow = NULL;
 
819
        verify_noerr( GetWindowProperty( inWindowRef, 'hifr', 'twin', sizeof( TWindow* ), NULL, &tWindow ) );
 
820
        return tWindow;
 
821
}
 
822
 
 
823
OSStatus
 
824
TWindow::GetLabelControlString(const int inID, std::string& value)
 
825
{
 
826
    return GetControlString(inID, kControlStaticTextTextTag, value);
 
827
}
 
828
 
 
829
OSStatus
 
830
TWindow::SetLabelControlString(const int inID, const std::string& value)
 
831
{
 
832
    return SetControlString(inID, kControlStaticTextTextTag, value);
 
833
}
 
834
 
 
835
OSStatus
 
836
TWindow::GetTextControlString(const int inID, std::string& value)
 
837
{
 
838
    return GetControlString(inID, kControlEditTextTextTag, value);
 
839
}
 
840
 
 
841
OSStatus
 
842
TWindow::SetTextControlString(const int inID, const std::string& value)
 
843
{
 
844
    return SetControlString(inID, kControlEditTextTextTag, value);
 
845
}
 
846
 
 
847
OSStatus
 
848
TWindow::GetPasswordControlString(const int inID, std::string& value)
 
849
{
 
850
    OSStatus err = noErr;
 
851
        ControlID controlID = { _appSignature, inID };
 
852
        ControlRef control = NULL;
 
853
        CFStringRef result = NULL;
 
854
    char* pszValue = NULL;
 
855
        
 
856
        err = GetControlByID(GetWindowRef(), &controlID, &control);
 
857
        if (err == noErr)
 
858
        {
 
859
                   err = GetControlData(control,
 
860
                                        kControlEntireControl,
 
861
                                                            kControlEditTextPasswordCFStringTag,
 
862
                                                            sizeof(result),
 
863
                                                            &result,
 
864
                                                            NULL);
 
865
               if (err == noErr)
 
866
                   {
 
867
                  CFIndex len = CFStringGetLength(result);
 
868
                          if (len > 0)
 
869
                          {
 
870
                             pszValue = new char[len+1];
 
871
                         if (CFStringGetCString(result, pszValue, len+1, kCFStringEncodingMacRoman))
 
872
                                 {
 
873
                                    value = pszValue;
 
874
                                        delete [] pszValue; pszValue = NULL;
 
875
                                 }
 
876
                          }
 
877
                   }
 
878
        }
 
879
        
 
880
        if (result)
 
881
        {
 
882
           CFRelease(result);
 
883
        }
 
884
        
 
885
        if (pszValue)
 
886
        {
 
887
           delete [] pszValue;
 
888
        }
 
889
        
 
890
        return err;
 
891
}
 
892
 
 
893
OSStatus
 
894
TWindow::SetPasswordControlString(const int inID, const std::string& value)
 
895
{
 
896
    OSStatus err = noErr;
 
897
        ControlID controlID = { _appSignature, inID };
 
898
        ControlRef control = NULL;
 
899
        CFStringRef cfVal = NULL;
 
900
        
 
901
        err = GetControlByID(GetWindowRef(), &controlID, &control);
 
902
        if (err == noErr)
 
903
        {
 
904
            cfVal = CFStringCreateWithCString(NULL, value.c_str(), kCFStringEncodingMacRoman);
 
905
                
 
906
                err = SetControlData(control,
 
907
                                                         kControlEntireControl,
 
908
                                                         kControlEditTextPasswordCFStringTag,
 
909
                                                         sizeof(cfVal),
 
910
                                                         &cfVal);
 
911
        }
 
912
        
 
913
        if (cfVal)
 
914
        {
 
915
           CFRelease(cfVal);
 
916
        }
 
917
        
 
918
        return err;
 
919
}
 
920
 
 
921
OSStatus
 
922
TWindow::GetControlString(const int inID, ResType resourceType, std::string& value)
 
923
{
 
924
    OSStatus err = noErr;
 
925
        ControlID controlID = { _appSignature, inID };
 
926
        ControlRef control = NULL;
 
927
        char* pszBuf = NULL;
 
928
 
 
929
        err = GetControlByID(GetWindowRef(), &controlID, &control);
 
930
        if (err == noErr)
 
931
        {
 
932
                Size actualSize;
 
933
                
 
934
                err = GetControlDataSize(control,
 
935
                                                                 kControlEntireControl,
 
936
                                                                 resourceType,
 
937
                                                                 &actualSize);
 
938
                if ((err == noErr) && actualSize > 0)
 
939
                {
 
940
                   pszBuf = new char[actualSize+1];
 
941
                   *pszBuf = '\0';
 
942
                
 
943
                   err = GetControlData(control,
 
944
                                        kControlEntireControl,
 
945
                                                            resourceType,
 
946
                                                            actualSize,
 
947
                                                            pszBuf,
 
948
                                                            &actualSize);
 
949
               if (err == noErr)
 
950
                   {
 
951
                      *(pszBuf+actualSize) = '\0';
 
952
                      value = pszBuf;
 
953
                   }
 
954
           }
 
955
        }
 
956
        
 
957
        if (pszBuf)
 
958
        {
 
959
                delete [] pszBuf;
 
960
        }
 
961
        
 
962
        return err;
 
963
}
 
964
 
 
965
OSStatus
 
966
TWindow::SetControlString(const int inID, ResType resourceType, const std::string& inValue)
 
967
{
 
968
    OSStatus err = noErr;
 
969
        ControlID controlID = { _appSignature, inID };
 
970
        ControlRef control = NULL;
 
971
        
 
972
        err = GetControlByID(GetWindowRef(), &controlID, &control);
 
973
        if (err == noErr)
 
974
        {
 
975
                err = SetControlData(control,
 
976
                                     kControlEntireControl,
 
977
                                                         resourceType,
 
978
                                                         inValue.length(),
 
979
                                                         inValue.length() ? inValue.c_str() : "");
 
980
        }
 
981
        
 
982
        return err;
 
983
}
 
984
 
 
985
OSStatus
 
986
TWindow::SetControlValue(const int inID, const SInt32 inValue)
 
987
{
 
988
    OSStatus err = noErr;
 
989
        ControlID controlID = { _appSignature, inID };
 
990
        ControlRef control = NULL;
 
991
        
 
992
        err = GetControlByID(GetWindowRef(), &controlID, &control);
 
993
        if (err == noErr)
 
994
        {
 
995
           SetControl32BitValue(control, inValue);
 
996
        }
 
997
        
 
998
        return err;
 
999
}
 
1000
 
 
1001
OSStatus
 
1002
TWindow::GetControlValue(const int inID, SInt32& outValue)
 
1003
{
 
1004
    OSStatus err = noErr;
 
1005
        ControlID controlID = { _appSignature, inID };
 
1006
        ControlRef control = NULL;
 
1007
        
 
1008
        err = GetControlByID(GetWindowRef(), &controlID, &control);
 
1009
        if (err == noErr)
 
1010
        {
 
1011
           outValue = GetControl32BitValue(control);
 
1012
        }
 
1013
        
 
1014
        return err;
 
1015
}
 
1016
 
 
1017
bool
 
1018
TWindow::IsRadioButtonSet(const int inID)
 
1019
{
 
1020
         SInt32 value = 0; 
 
1021
         return (noErr == GetControlValue(inID, value)) && (value != 0);
 
1022
}
 
1023
 
 
1024
OSStatus
 
1025
TWindow::EnableLocalControl(const int inID)
 
1026
{
 
1027
    OSStatus err = noErr;
 
1028
        ControlID controlID = { _appSignature, inID };
 
1029
        ControlRef control = NULL;
 
1030
        
 
1031
        err = GetControlByID(GetWindowRef(), &controlID, &control);
 
1032
        if (err == noErr)
 
1033
        {
 
1034
           err = EnableControl(control);
 
1035
        }
 
1036
        
 
1037
        return err;
 
1038
}
 
1039
 
 
1040
OSStatus
 
1041
TWindow::DisableLocalControl(const int inID)
 
1042
{
 
1043
    OSStatus err = noErr;
 
1044
        ControlID controlID = { _appSignature, inID };
 
1045
        ControlRef control = NULL;
 
1046
        
 
1047
        err = GetControlByID(GetWindowRef(), &controlID, &control);
 
1048
        if (err == noErr)
 
1049
        {
 
1050
           err = DisableControl(control);
 
1051
        }
 
1052
        
 
1053
        return err;
 
1054
}
 
1055
 
 
1056
OSStatus
 
1057
TWindow::PostApplicationEvent(const int cmdID)
 
1058
{
 
1059
    OSStatus err = noErr;
 
1060
    EventRef event;
 
1061
        
 
1062
        err = CreateEvent(NULL, kEventClassCommand, kEventCommandProcess, GetCurrentEventTime(), 0, &event);
 
1063
        if (err == noErr)
 
1064
        {
 
1065
           HICommand command;
 
1066
        
 
1067
           BlockZero(&command, sizeof(command));
 
1068
           command.commandID = cmdID;
 
1069
                
 
1070
           SetEventParameter(event, kEventParamDirectObject, typeHICommand, sizeof(command), &command);
 
1071
 
 
1072
           SendEventToEventTarget(event, GetApplicationEventTarget());
 
1073
           ReleaseEvent(event);
 
1074
        }
 
1075
        
 
1076
        return err;
 
1077
}
 
1078
 
 
1079
OSStatus
 
1080
TWindow::PostWindowEvent(const int cmdID, WindowRef window)
 
1081
{
 
1082
        OSStatus err = noErr;
 
1083
    EventRef event;
 
1084
        
 
1085
        err = CreateEvent(NULL, kEventClassCommand, kEventCommandProcess, GetCurrentEventTime(), kEventAttributeUserEvent, &event);
 
1086
        if (err == noErr)
 
1087
        {
 
1088
                HICommand command;
 
1089
        
 
1090
            BlockZero(&command, sizeof(command));
 
1091
            command.commandID = cmdID;
 
1092
                
 
1093
                SetEventParameter(event, kEventParamDirectObject, typeHICommand, sizeof(command), &command);
 
1094
                
 
1095
            SendEventToEventTarget(event, GetWindowEventTarget(window));
 
1096
            ReleaseEvent(event);
 
1097
        }
 
1098
        
 
1099
        return err;
 
1100
}
 
1101