diff options
Diffstat (limited to 'fpicker/source/aqua/ControlHelper.cxx')
-rw-r--r-- | fpicker/source/aqua/ControlHelper.cxx | 166 |
1 files changed, 83 insertions, 83 deletions
diff --git a/fpicker/source/aqua/ControlHelper.cxx b/fpicker/source/aqua/ControlHelper.cxx index 15b01c88db95..67725c19ecf2 100644 --- a/fpicker/source/aqua/ControlHelper.cxx +++ b/fpicker/source/aqua/ControlHelper.cxx @@ -2,7 +2,7 @@ /************************************************************************* * * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * + * * Copyright 2000, 2010 Oracle and/or its affiliates. * * OpenOffice.org - a multi-platform office productivity suite @@ -79,7 +79,7 @@ ControlHelper::ControlHelper() ControlHelper::~ControlHelper() { DBG_PRINT_ENTRY(CLASS_NAME, __func__); - + NSAutoreleasePool *pool = [NSAutoreleasePool new]; if (NULL != m_pUserPane) { @@ -104,7 +104,7 @@ ControlHelper::~ControlHelper() if (m_pFilterControl != NULL) { [m_pFilterControl setTarget:nil]; } - + [pool release]; DBG_PRINT_EXIT(CLASS_NAME, __func__); @@ -176,7 +176,7 @@ void ControlHelper::enableControl( const sal_Int16 nControlId, const sal_Bool bE DBG_PRINT_EXIT(CLASS_NAME, __func__); return; } - + NSControl* pControl = getControl(nControlId); if( pControl != nil ) { @@ -227,18 +227,18 @@ void ControlHelper::setLabel( sal_Int16 nControlId, const NSString* aLabel ) DBG_PRINT_ENTRY(CLASS_NAME, __func__, "controlId", nControlId, "label", aLabel); SolarMutexGuard aGuard; - + NSAutoreleasePool *pool = [NSAutoreleasePool new]; NSControl* pControl = getControl(nControlId); - + if (nil != pControl) { if ([pControl class] == [NSPopUpButton class]) { NSString *sOldName = m_aMapListLabels[pControl]; if (sOldName != NULL && sOldName != aLabel) { [sOldName release]; } - + m_aMapListLabels[pControl] = [aLabel retain]; } else if ([pControl class] == [NSButton class]) { [[pControl cell] setTitle:aLabel]; @@ -248,7 +248,7 @@ void ControlHelper::setLabel( sal_Int16 nControlId, const NSString* aLabel ) } layoutControls(); - + [pool release]; DBG_PRINT_EXIT(CLASS_NAME, __func__); @@ -318,50 +318,50 @@ uno::Any ControlHelper::getValue( sal_Int16 nControlId, sal_Int16 nControlAction void ControlHelper::createUserPane() { DBG_PRINT_ENTRY(CLASS_NAME, __func__); - + if (m_bUserPaneNeeded == false) { OSL_TRACE("no user pane needed"); DBG_PRINT_EXIT(CLASS_NAME, __func__); return; } - + if (nil != m_pUserPane) { OSL_TRACE("user pane already exists"); DBG_PRINT_EXIT(CLASS_NAME, __func__); return; } - + if (m_bIsFilterControlNeeded == true && m_pFilterControl == nil) { createFilterControl(); } - + NSRect minRect = NSMakeRect(0,0,300,33); m_pUserPane = [[NSView alloc] initWithFrame:minRect]; int currentHeight = kAquaSpaceBoxFrameViewDiffTop + kAquaSpaceBoxFrameViewDiffBottom; int currentWidth = 300; - + BOOL bPopupControlPresent = NO; BOOL bButtonControlPresent = NO; - + int nCheckboxMaxWidth = 0; int nPopupMaxWidth = 0; int nPopupLabelMaxWidth = 0; - + for (::std::list<NSControl*>::iterator child = m_aActiveControls.begin(); child != m_aActiveControls.end(); child++) { OSL_TRACE("currentHeight: %d", currentHeight); - + NSControl* pControl = *child; - + //let the control calculate its size [pControl sizeToFit]; - + NSRect frame = [pControl frame]; OSL_TRACE("frame for control %s is {%f, %f, %f, %f}", [[pControl description] UTF8String], frame.origin.x, frame.origin.y, frame.size.width, frame.size.height); - + int nControlHeight = frame.size.height; int nControlWidth = frame.size.width; - + // Note: controls are grouped by kind, first all popup menus, then checkboxes if ([pControl class] == [NSPopUpButton class]) { if (bPopupControlPresent == YES) { @@ -371,78 +371,78 @@ void ControlHelper::createUserPane() else if (child != m_aActiveControls.begin()){ currentHeight += kAquaSpaceBetweenControls; } - + bPopupControlPresent = YES; - + // we have to add the label text width NSString *label = m_aMapListLabels[pControl]; - + NSTextField *textField = createLabelWithString(label); [textField sizeToFit]; m_aMapListLabelFields[(NSPopUpButton*)pControl] = textField; [m_pUserPane addSubview:textField]; - + NSRect tfRect = [textField frame]; OSL_TRACE("frame for textfield %s is {%f, %f, %f, %f}", [[textField description] UTF8String], tfRect.origin.x, tfRect.origin.y, tfRect.size.width, tfRect.size.height); - + int tfWidth = tfRect.size.width; - + if (nPopupLabelMaxWidth < tfWidth) { nPopupLabelMaxWidth = tfWidth; } - + frame.origin.x += (kAquaSpaceBetweenControls - kAquaSpaceLabelFrameBoundsDiffH - kAquaSpacePopupMenuFrameBoundsDiffLeft) + tfWidth; - + if (nControlWidth < POPUP_WIDTH_MIN) { nControlWidth = POPUP_WIDTH_MIN; frame.size.width = nControlWidth; [pControl setFrame:frame]; } - + if (nControlWidth > POPUP_WIDTH_MAX) { nControlWidth = POPUP_WIDTH_MAX; frame.size.width = nControlWidth; [pControl setFrame:frame]; } - + //set the max size if (nPopupMaxWidth < nControlWidth) { nPopupMaxWidth = nControlWidth; } - + nControlWidth += tfWidth + kAquaSpaceBetweenControls - kAquaSpaceLabelFrameBoundsDiffH - kAquaSpacePopupMenuFrameBoundsDiffLeft; if (nControlHeight < kAquaPopupButtonDefaultHeight) { //maybe the popup has no menu item yet, so set a default height nControlHeight = kAquaPopupButtonDefaultHeight; } - + nControlHeight -= kAquaSpacePopupMenuFrameBoundsDiffV; } else if ([pControl class] == [NSButton class]) { if (child != m_aActiveControls.begin()){ currentHeight += kAquaSpaceBetweenControls; } - + if (nCheckboxMaxWidth < nControlWidth) { nCheckboxMaxWidth = nControlWidth; } - + bButtonControlPresent = YES; nControlWidth -= 2 * kAquaSpaceSwitchButtonFrameBoundsDiff; nControlHeight -= 2 * kAquaSpaceSwitchButtonFrameBoundsDiff; } - + // if ((nControlWidth + 2 * kAquaSpaceInsideGroupH) > currentWidth) { // currentWidth = nControlWidth + 2 * kAquaSpaceInsideGroupH; // } - + currentHeight += nControlHeight; - + [m_pUserPane addSubview:pControl]; } - + OSL_TRACE("height after adding all controls: %d", currentHeight); - + if (bPopupControlPresent && bButtonControlPresent) { //after a popup button (array) and before a different kind of control we need some extra space instead of the standard @@ -450,20 +450,20 @@ void ControlHelper::createUserPane() currentHeight += kAquaSpaceAfterPopupButtonsV; OSL_TRACE("popup extra space added, currentHeight: %d", currentHeight); } - + int nLongestPopupWidth = nPopupMaxWidth + nPopupLabelMaxWidth + kAquaSpaceBetweenControls - kAquaSpacePopupMenuFrameBoundsDiffLeft - kAquaSpaceLabelFrameBoundsDiffH; - + currentWidth = nLongestPopupWidth > nCheckboxMaxWidth ? nLongestPopupWidth : nCheckboxMaxWidth; OSL_TRACE("longest control width: %d", currentWidth); - + currentWidth += 2* kAquaSpaceInsideGroupH; if (currentWidth < minRect.size.width) currentWidth = minRect.size.width; - + if (currentHeight < minRect.size.height) currentHeight = minRect.size.height; - + NSRect upRect = NSMakeRect(0, 0, currentWidth, currentHeight ); OSL_TRACE("setting user pane rect to {%f, %f, %f, %f}",upRect.origin.x, upRect.origin.y, upRect.size.width, upRect.size.height); @@ -489,7 +489,7 @@ void ControlHelper::createControls() int elementName = getControlElementName([NSPopUpButton class], i); NSString* sLabel = aResProvider.getResString(elementName); - + m_pListControls[i] = [NSPopUpButton new]; #define MAP_LIST_( elem ) \ @@ -518,31 +518,31 @@ void ControlHelper::createControls() NSButton *button = [NSButton new]; [button setTitle:sLabel]; - + [button setButtonType:NSSwitchButton]; - + [button setState:NSOffState]; - + if (i == AUTOEXTENSION) { [button setTarget:m_pDelegate]; [button setAction:@selector(autoextensionChanged:)]; } - + m_pToggles[i] = button; - + m_aActiveControls.push_back(m_pToggles[i]); } else { m_pToggles[i] = nil; } } - + //preview is always on with Mac OS X NSControl *pPreviewBox = m_pToggles[PREVIEW]; if (pPreviewBox != nil) { [pPreviewBox setEnabled:NO]; [(NSButton*)pPreviewBox setState:NSOnState]; } - + DBG_PRINT_EXIT(CLASS_NAME, __func__); } @@ -597,7 +597,7 @@ void ControlHelper::HandleSetListValue(const NSControl* pControl, const sal_Int1 DBG_PRINT_EXIT(CLASS_NAME, __func__); return; } - + NSPopUpButton *pButton = (NSPopUpButton*)pControl; NSMenu *rMenu = [pButton menu]; if (nil == rMenu) { @@ -686,7 +686,7 @@ uno::Any ControlHelper::HandleGetListValue(const NSControl* pControl, const sal_ DBG_PRINT_EXIT(CLASS_NAME, __func__); return aAny; } - + NSPopUpButton *pButton = (NSPopUpButton*)pControl; NSMenu *rMenu = [pButton menu]; if (nil == rMenu) { @@ -804,7 +804,7 @@ case ExtendedFilePickerElementIds::LISTBOX_##elem##_LABEL: \ void ControlHelper::layoutControls() { DBG_PRINT_ENTRY(CLASS_NAME, __func__); - + SolarMutexGuard aGuard; if (nil == m_pUserPane) { @@ -812,32 +812,32 @@ void ControlHelper::layoutControls() DBG_PRINT_EXIT(CLASS_NAME, __func__); return; } - + if (m_bIsUserPaneLaidOut == true) { OSL_TRACE("user pane already laid out"); DBG_PRINT_EXIT(CLASS_NAME, __func__); return; } - + NSRect userPaneRect = [m_pUserPane frame]; OSL_TRACE("userPane frame: {%f, %f, %f, %f}",userPaneRect.origin.x, userPaneRect.origin.y, userPaneRect.size.width, userPaneRect.size.height); - + int nUsableWidth = userPaneRect.size.width; - + //NOTE: NSView's coordinate system starts in the lower left hand corner but we start adding controls from the top, // so we subtract from the vertical position as we make our way down the pane. int currenttop = userPaneRect.size.height; int nCheckboxMaxWidth = 0; int nPopupMaxWidth = 0; int nPopupLabelMaxWidth = 0; - + //first loop to determine max sizes for (::std::list<NSControl*>::iterator child = m_aActiveControls.begin(); child != m_aActiveControls.end(); child++) { NSControl* pControl = *child; - + NSRect controlRect = [pControl frame]; int nControlWidth = controlRect.size.width; - + Class aSubType = [pControl class]; if (aSubType == [NSPopUpButton class]) { if (nPopupMaxWidth < nControlWidth) { @@ -855,34 +855,34 @@ void ControlHelper::layoutControls() } } } - + int nLongestPopupWidth = nPopupMaxWidth + nPopupLabelMaxWidth + kAquaSpaceBetweenControls - kAquaSpacePopupMenuFrameBoundsDiffLeft - kAquaSpaceLabelFrameBoundsDiffH; OSL_TRACE("longest popup width: %d", nLongestPopupWidth); NSControl* previousControl = nil; - + int nDistBetweenControls = 0; - + for (::std::list<NSControl*>::iterator child = m_aActiveControls.begin(); child != m_aActiveControls.end(); child++) { NSControl* pControl = *child; - + //get the control's bounds NSRect controlRect = [pControl frame]; int nControlHeight = controlRect.size.height; int nControlWidth = controlRect.size.width; - + //subtract the height from the current vertical position, because the control's bounds origin rect will be its lower left hand corner currenttop -= nControlHeight; Class aSubType = [pControl class]; - + //add space between the previous control and this control according to Apple's HIG nDistBetweenControls = getVerticalDistance(previousControl, pControl); OSL_TRACE("vertical distance: %d", nDistBetweenControls); currenttop -= nDistBetweenControls; - + previousControl = pControl; - + if (aSubType == [NSPopUpButton class]) { //move vertically up some pixels to space the controls between their real (visual) bounds currenttop += kAquaSpacePopupMenuFrameBoundsDiffTop;//from top @@ -935,12 +935,12 @@ void ControlHelper::createFilterControl() { NSString* sLabel = aResProvider.getResString(CommonFilePickerElementIds::LISTBOX_FILTER_LABEL); m_pFilterControl = [NSPopUpButton new]; - + [m_pFilterControl setAction:@selector(filterSelectedAtIndex:)]; [m_pFilterControl setTarget:m_pDelegate]; - + NSMenu *menu = [m_pFilterControl menu]; - + for (NSStringList::iterator iter = m_pFilterHelper->getFilterNames()->begin(); iter != m_pFilterHelper->getFilterNames()->end(); iter++) { NSString *filterName = *iter; OSL_TRACE("adding filter name: %s", [filterName UTF8String]); @@ -951,11 +951,11 @@ void ControlHelper::createFilterControl() { [m_pFilterControl addItemWithTitle:filterName]; } } - + // always add the filter as first item m_aActiveControls.push_front(m_pFilterControl); m_aMapListLabels[m_pFilterControl] = [sLabel retain]; - + DBG_PRINT_EXIT(CLASS_NAME, __func__); } @@ -968,7 +968,7 @@ NSTextField* ControlHelper::createLabelWithString(const NSString* labelString) { [textField setDrawsBackground:NO]; [textField setBordered:NO]; [[textField cell] setTitle:labelString]; - + DBG_PRINT_EXIT(CLASS_NAME, __func__); return textField; } @@ -984,7 +984,7 @@ int ControlHelper::getVerticalDistance(const NSControl* first, const NSControl* else { Class firstClass = [first class]; Class secondClass = [second class]; - + if (firstClass == [NSPopUpButton class]) { if (secondClass == [NSPopUpButton class]) { return kAquaSpaceBetweenPopupMenus; @@ -993,7 +993,7 @@ int ControlHelper::getVerticalDistance(const NSControl* first, const NSControl* return kAquaSpaceAfterPopupButtonsV; } } - + return kAquaSpaceBetweenControls; } } @@ -1001,21 +1001,21 @@ int ControlHelper::getVerticalDistance(const NSControl* first, const NSControl* void ControlHelper::updateFilterUI() { DBG_PRINT_ENTRY(CLASS_NAME, __func__); - + if (m_bIsFilterControlNeeded == false || m_pFilterHelper == NULL) { OSL_TRACE("no filter control needed or no filter helper present"); DBG_PRINT_EXIT(CLASS_NAME, __func__); return; } - + int index = m_pFilterHelper->getCurrentFilterIndex(); - + if (m_pFilterControl == nil) { createFilterControl(); } - + [m_pFilterControl selectItemAtIndex:index]; - + DBG_PRINT_EXIT(CLASS_NAME, __func__); } |