ResKnife/Template Editor/Classes/TemplateWindow.cpp

1 line
61 KiB
C++
Raw Normal View History

2001-10-19 19:41:13 +00:00
#include "TemplateWindow.h" /*** CREATOR ***/ TemplateWindow::TemplateWindow( WindowRef newWindow ) { // clear all instance bytes BlockZero( this, sizeof(TemplateWindow) ); // set the window to the one just created window = newWindow; } /*** DESTRUCTOR ***/ TemplateWindow::~TemplateWindow( void ) { ReadControls(); } /*** USE TEMPLATE ***/ OSStatus TemplateWindow::UseTemplate( Handle newTmpl ) { tmpl = newTmpl; return noErr; } /*** PARSE DATA ***/ OSStatus TemplateWindow::ParseData( Handle data ) { #pragma unused( data ) OSStatus error = noErr; error = ParseTemplate(); error = CreateControls(); return error; } /*** PARSE TEMPLATE ***/ OSStatus TemplateWindow::ParseTemplate( void ) { SInt32 size = GetHandleSize( tmpl ); SInt8 state = HGetState( tmpl ); HLock( tmpl ); ElementPtr current = elements = new Element; elementCount++; unsigned long position = 0; // start parsing at offset zero (unsurprisingly) while( position < size ) { // fill in element data short labelSize = *(*tmpl + position); BlockMoveData( *tmpl + position, &current->label, labelSize +1 ); position += labelSize +1; // don't forget length byte! BlockMoveData( *tmpl + position, &current->type, sizeof(ResType) ); position += sizeof(ResType); // but restype is always 4 bytes :) // create new element if( position < size ) { elementCount++; current->next = new Element; current = current->next; } } // clean up HSetState( tmpl, state ); return noErr; } /*** CREATE CONTROLS ***/ OSStatus TemplateWindow::CreateControls( void ) { OSStatus error = noErr; ControlRef root, label, secondaryLabel, group, radio, checkbox, edit, listcount; CreateRootControl( window, &root ); Rect windowBounds, rect, secondaryLabelRect; GetWindowPortBounds( window, &windowBounds ); // get resource data (the really tedious way - I ought to make this easier) Plug_WindowRef plugWindow = Host_GetPlugWindowFromWindowRef( window ); if( plugWindow == null ) DebugStr("\pplugWindow == null"); Plug_ResourceRef resource = Host_GetTargetResource( plugWindow ); if( resource == null ) DebugStr("\presource == null"); Handle data = Host_GetResourceData( resource ); SInt32 size = GetHandleSize( data ); SInt8 state = HGetState( data ); HLock( data ); // set control font style ControlID id; ControlFontStyleRec fontStyle, rectLabelStyle; fontStyle.flags = kControlUseFontMask + kControlUseJustMask; fontStyle.font = kControlFontSmallSystemFont; fontStyle.just = teJustLeft; rectLabelStyle.flags = kControlUseFontMask + kControlUseJustMask; rectLabelStyle.font = kControlFontSmallSystemFont; rectLabelStyle.just = teJustRight; // set up bounds for first control bounds.top = bounds.bottom = windowBounds.top; // bounds.top is ignored, bounds.bottom is the bottom of the previous control bounds.left = windowBounds.left +110 + 8; // bounds.left and .right are the sides of the controls excluding the label bounds.right = windowBounds.right - 8; // declare variables CFStringRef text = null; signed long position = 0; // offset of data currently being processed unsigned char boolBit = 0; ElementPtr current = elements; ElementPtr recursionOrigin = null; // bug: only handles one level of recursion signed long recursionTotal = 0; unsigned long recursionIndex = 0, recursionCount = 0; unsigned long m = 0, n = 0; // counters, one is always unique, the other is an element index for( ; m < elementCount; m++ ) { n++; // advance unique counter // create controls switch( current->type ) { case 'BOOL': // BOOL is two bytes long, false == 0x0000, true == 0x0100 { Boolean valid = false; if( size > position ) valid = (Boolean) ((unsigned short) *(*data + position)) > 0; SetRect( &rect, bounds.left, bounds.bottom +8, bounds.right, bounds.bottom + 2*16 +12 ); CreateRadioGroupControl( window, &rect, &group ); SetRect( &rect, rect.left, rect.top, rect.right, rect.top +16 ); error = CreateRadioButtonControl( window, &rect, CFSTR("False"), !valid, true, &radio ); // false is embedded at ind