⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 easytab.c

📁 基于Labwindows的电池故障诊断系统
💻 C
📖 第 1 页 / 共 5 页
字号:
                }

            availableGapSpace = maxRowWidth - minRowWidth;
            
            if (group->buttonGap >= 0)
                gapSpace = Min((numSheets - 1) * group->buttonGap, availableGapSpace);
            else
                gapSpace = availableGapSpace;
                
            if (group->sizeButtonsToFillRows)
                stretchSpace = availableGapSpace - gapSpace;
            else
                stretchSpace = 0;
                
            for (sheetIndex  = 1; sheetIndex <= numSheets; sheetIndex++)
                {
                numSheetsLeft = numSheets - sheetIndex;
                ListGetItem(sheetList, &sheet, sheetIndex);
                tabButton = sheet->tabButton;
            
                TabButton_GetMinBounds(tabButton, FALSE, &minBounds);
                
                relBounds.top = relVOffset - minBounds.height;
                relBounds.left = relHOffset;
                    
                relBounds.height = 0 - relBounds.top;
                
                
                thisStretchSpace = stretchSpace / (numSheetsLeft + 1);
                stretchSpace -= thisStretchSpace;
                relBounds.width  = minBounds.width + thisStretchSpace;
                
                if (numSheetsLeft > 0)
                    thisGapSpace = (gapSpace / numSheetsLeft);
                else
                    thisGapSpace = 0;
                gapSpace -= thisGapSpace;
                
                relHOffset += thisGapSpace + relBounds.width;
            
                switch (group->buttonPosition)
                    {
                    case VAL_EASY_TAB_BTNS_ON_TOP:
                        buttonBounds = relBounds;
                        break;
                    case VAL_EASY_TAB_BTNS_ON_BOTTOM:
                        buttonBounds = relBounds;
                        buttonBounds.top = group->frameRect.height; 
                        break;
                    case VAL_EASY_TAB_BTNS_ON_RIGHT:
                        buttonBounds.left = group->frameRect.width;
                        buttonBounds.width = relBounds.height;
                        buttonBounds.top = relBounds.left;
                        buttonBounds.height = relBounds.width;
                        break;
                    case VAL_EASY_TAB_BTNS_ON_LEFT:
                        buttonBounds.left = relBounds.top;
                        buttonBounds.width = relBounds.height;
                        buttonBounds.top = group->frameRect.height - relBounds.left - relBounds.width;
                        buttonBounds.height = relBounds.width;
                        break;
                    }

                TabButton_SetBounds(tabButton, buttonBounds);
            
                if (RectEmpty(unionRect))
                    unionRect = buttonBounds;
                else
                    RectUnion(buttonBounds, unionRect, &unionRect);
                }
            
                relVOffset -= minBounds.height; /* use minBounds, because buttonBounds may have been vertical extended if group->sizeButtonsToFillRows is FALSE */
            }

        group->tabButtonPositionsCalculated = TRUE;
        
        if (!RectEmpty(unionRect))
            {
            if (numRows == 1)    /* need extra for when tab is active */
                switch (group->buttonPosition)
                    {
                    case VAL_EASY_TAB_BTNS_ON_TOP:
                        unionRect.height += TABBUTTON_ACTIVE_EXTRA_TOP;
                        unionRect.top -= TABBUTTON_ACTIVE_EXTRA_TOP;
                        break;
                    case VAL_EASY_TAB_BTNS_ON_BOTTOM:
                        unionRect.height += TABBUTTON_ACTIVE_EXTRA_TOP;
                        break;
                    case VAL_EASY_TAB_BTNS_ON_RIGHT:
                        unionRect.width += TABBUTTON_ACTIVE_EXTRA_TOP;
                        break;
                    case VAL_EASY_TAB_BTNS_ON_LEFT:
                        unionRect.width += TABBUTTON_ACTIVE_EXTRA_TOP;
                        unionRect.left -= TABBUTTON_ACTIVE_EXTRA_TOP;
                        break;
                    }
                
            eraseRect = unionRect;
            switch (group->buttonPosition)
                {
                case VAL_EASY_TAB_BTNS_ON_TOP:
                case VAL_EASY_TAB_BTNS_ON_BOTTOM:
                    if (!activeSheetIsRightMost)
                        eraseRect.width  += TABBUTTON_ACTIVE_EXTRA_RIGHT;
                    if (!activeSheetIsLeftMost)
                        {
                        eraseRect.width  += TABBUTTON_ACTIVE_EXTRA_LEFT;
                        eraseRect.left  -= TABBUTTON_ACTIVE_EXTRA_LEFT;
                        }
                    break;
                case VAL_EASY_TAB_BTNS_ON_RIGHT:
                    if (!activeSheetIsRightMost)
                        eraseRect.height += TABBUTTON_ACTIVE_EXTRA_RIGHT;
                    if (!activeSheetIsLeftMost)
                        {
                        eraseRect.height += TABBUTTON_ACTIVE_EXTRA_LEFT;
                        eraseRect.top -= TABBUTTON_ACTIVE_EXTRA_LEFT;
                        }
                    break;
                case VAL_EASY_TAB_BTNS_ON_LEFT:
                    if (!activeSheetIsRightMost)
                        {
                        eraseRect.height += TABBUTTON_ACTIVE_EXTRA_RIGHT;
                        eraseRect.top -= TABBUTTON_ACTIVE_EXTRA_RIGHT;
                        }
                    if (!activeSheetIsLeftMost)
                        eraseRect.height += TABBUTTON_ACTIVE_EXTRA_LEFT;
                    break;
                }
            }
        group->tabButtonBoundsUnion = unionRect;
        group->tabButtonEraseArea = eraseRect;
        }
        
Error:
    return error;
}

/*************************************************************/

static TabButton TabButton_Create(Sheet sheet, const char *label)
{
    int         error = UIENoError;
    TabButton   tabButton = 0;
    
    nullChk( tabButton = (TabButton)calloc(sizeof(*tabButton), 1));
    tabButton->signature = TAB_BUTTON_SIGNATURE;
    tabButton->sheet = sheet;
    tabButton->dimmed = FALSE;
    tabButton->tabColor = -1;
    errChk( TabButton_SetLabel(tabButton, label));

Error:
    if (error < 0)
        {
        TabButton_Dispose(tabButton);
        tabButton = NULL;
        }
    
    return tabButton;
}

/*************************************************************/

static void TabButton_Dispose(TabButton tabButton)
{
    if (tabButton)
        {
        free(tabButton->label);
        free(tabButton->displayLabel);
        if (tabButton->bitmap != 0)
            DiscardBitmap(tabButton->bitmap);
        free(tabButton);
        }
}

/*************************************************************/

static int TabButton_SetLabel(TabButton tabButton, const char *label)
{
    int     error = UIENoError;
    char    *newLabel = 0;
    char    *newDisplayLabel = 0;
    int     underlinePos;
    char    savedChar;
    char    accelKeyStr[2];
    
    nullChk( newLabel = StrDup(label));
    nullChk( newDisplayLabel = StrDup(label));

    free(tabButton->label);
    free(tabButton->displayLabel);
    if (tabButton->bitmap != 0)
        {
        DiscardBitmap(tabButton->bitmap);
        tabButton->bitmap = 0;
        }
    
    tabButton->label = newLabel;
    tabButton->displayLabel = newDisplayLabel;
    
    RemoveAcceleratorEscapeCode(newDisplayLabel);
    underlinePos = AcceleratorEscapeCodeLocation(newLabel);
    
    if (underlinePos >= 0)
        {
        tabButton->acceleratorKey = newDisplayLabel[underlinePos];
        savedChar = newDisplayLabel[underlinePos];
        newDisplayLabel[underlinePos] = 0;  /* NULL terminate string before underline character for call to GetTextDisplaySize */
        GetTextDisplaySize (newDisplayLabel, tabButton->sheet->group->metaFont, 0, &tabButton->underlineOffset);
        newDisplayLabel[underlinePos] = savedChar;  /* fix label */
        
        accelKeyStr[0] = tabButton->acceleratorKey;
        accelKeyStr[1] = 0; /* NULL terminator */
        GetTextDisplaySize (accelKeyStr, tabButton->sheet->group->metaFont, 0, &tabButton->underlineWidth);
        }
    else
        tabButton->acceleratorKey = 0;
    
    GetTextDisplaySize (newDisplayLabel, tabButton->sheet->group->metaFont, 
                            &tabButton->labelSize.y, &tabButton->labelSize.x);
                            
    tabButton->minSize = tabButton->labelSize;
    tabButton->minSize.x += TABBUTTON_LEFT_MARGIN + TABBUTTON_RIGHT_MARGIN;
    tabButton->minSize.y += TABBUTTON_TOP_MARGIN + TABBUTTON_BOTTOM_MARGIN;
    
    EasyTab_InvalAll(tabButton->sheet->group);

Error:
    return error;
}

/*************************************************************/

    /*  all pixels values that are not VAL_TRANSPARENT will converted to the specified color. */
static int CreateTransparentOneColorBitmap(int *pixels, int color, int height, int width, int *bitmap)
{
    int             error = UIENoError;
    unsigned char   *bits = 0;
    int             rowBytes;
    int             h, w;
    int             bitNum;
    unsigned char   *rowPtr;
    unsigned char   byte;
    int             colorTable[2];
    int             numBytes;

    *bitmap = 0;
    rowBytes = (width + 7) / 8;             /* how many bytes are needed (8 monochrome pixels per byte) */
    if (rowBytes & 0x01)
        rowBytes++;                         /* round up to nearest 2 byte boundary */
    numBytes = rowBytes * height;
    nullChk(bits = malloc(numBytes));
    
    colorTable[0] = VAL_GREEN;  /* all zero bits should be eliminated by the mask anyway */
    colorTable[1] = color;
    
    for (h = 0; h < height; h++)
        {
        rowPtr = bits + h * rowBytes;
        bitNum = 7;
        byte = 0;

        for (w = 0; w < width; w++)
            {
            if (pixels[h*width + w] != VAL_TRANSPARENT)
                byte |= 1 << bitNum;
            
            bitNum--;
            if (bitNum < 0)
                {
                *rowPtr = byte;
                rowPtr++;
                bitNum = 7;
                byte = 0;
                }
            }
        if (bitNum != 7)
            *rowPtr = byte;     /* finish last partial byte */
        }
    
    errChk( NewBitmap (rowBytes, 1, width, height, colorTable, bits, bits, bitmap));
    
Error:
    free(bits);
    return error;
}

/*************************************************************/

static int TabButton_GetTextCanvas(int *panel, int *canvas, Point size)
{
    int         error = UIENoError;
    int         textPanel = *panel;
    int         textCanvas = *canvas;

    if (textPanel <= 0)
        errChk( textPanel = NewPanel(0, "", 40,40, 100, 100));
        
    if (textCanvas <= 0)
        {
        errChk( textCanvas = NewCtrl (textPanel, CTRL_CANVAS, "", 50, 0));
        SetCtrlAttribute(textPanel, textCanvas, ATTR_PICT_BGCOLOR, VAL_TRANSPARENT);
        }
        
    SetCtrlAttribute(textPanel, textCanvas, ATTR_HEIGHT, size.y);
    SetCtrlAttribute(textPanel, textCanvas, ATTR_WIDTH, size.x);
    *panel = textPanel;
    *canvas = textCanvas;
    
Error:
    return error;
}

/*************************************************************/

    /*  The pixels array is reallocated and the values of height and width are change to 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -