CSize CToolBarXP::CalcDynamicLayout (int nLength, DWORD dwMode) { bool bHideControls = (dwMode & LM_VERTDOCK) == LM_VERTDOCK; m_bCheckVisibility = (BYTE)(bHideControls ? 1 : 2); CSize size = CToolBar::CalcDynamicLayout (nLength, dwMode); m_bCheckVisibility = false; if ( dwMode & LM_COMMIT ) { TBBUTTON tbbutton; int nCount = DefWindowProc (TB_BUTTONCOUNT, 0, 0); for ( int i = 0; i < nCount; i++ ) { VERIFY(DefWindowProc (TB_GETBUTTON, i, (LPARAM)&tbbutton)); if ( !IS_CONTROL(tbbutton) ) { continue; } CWnd* pWnd = GetDlgItem (tbbutton.idCommand); if ( pWnd == NULL ) { continue; } if ( bHideControls ) { GetToolBarCtrl().HideButton (tbbutton.idCommand, true); pWnd->ShowWindow (SW_HIDE); } else { GetToolBarCtrl().HideButton (tbbutton.idCommand, false); // Update control position CRect rcControl; VERIFY (DefWindowProc (TB_GETITEMRECT, i, (LPARAM)&rcControl)); rcControl.DeflateRect (1, 1); CWindowRect rcCtrl (pWnd); int nNoSize = 0; if ( rcControl.Width() == rcCtrl.Width() ) { nNoSize = SWP_NOSIZE; } pWnd->SetWindowPos (NULL, rcControl.left, rcControl.top, rcControl.Width(), rcControl.Height(), nNoSize|SWP_NOACTIVATE|SWP_NOZORDER|SWP_SHOWWINDOW); } } } return size; }
LRESULT CToolBarXP::DefWindowProc (UINT nMsg, WPARAM wParam, LPARAM lParam) { LRESULT lRes = CToolBar::DefWindowProc (nMsg, wParam, lParam); if ( m_bCheckVisibility && nMsg == TB_GETBUTTON ) { TBBUTTON* pButton = (TBBUTTON*)lParam; if ( IS_CONTROL(*pButton) ) { if ( m_bCheckVisibility == 1 ) pButton->fsState |= TBSTATE_HIDDEN; else pButton->fsState &= ~TBSTATE_HIDDEN; } } return lRes; }
void expression_print(EXPRESSION expression) { int e = 0; while(expression[e].type != END) { if(IS_OPERATOR(expression[e].type) || IS_CONTROL(expression[e].type)) { printf("%c",expression[e].type); } else if(expression[e].type == VALUE) { printf("{%g}",expression[e].value); } else if(expression[e].type >= SUBSTITUTE_ZERO) { printf("{$%i}",expression[e].type - SUBSTITUTE_ZERO); } e ++; } }
/////////////////////////////////////////////////////////////////////////////// // Paint the toolbar void CToolBarXP::OnPaint () { if ( m_bDelayedButtonLayout ) { Layout(); } CPaintDC cpDC (this); CBufferDC cDC (cpDC); CRect rcClip; cDC.GetClipBox (rcClip); cDC.SetBkMode (TRANSPARENT); cDC.SelectObject (CFont::FromHandle ((HFONT)GetStockObject (DEFAULT_GUI_FONT))); cDC.FillSolidRect (rcClip, HLS_TRANSFORM (::GetSysColor (COLOR_3DFACE), 20, 0)); CPoint ptCursor; ::GetCursorPos (&ptCursor); ScreenToClient (&ptCursor); CClientRect rcClient (this); HIMAGELIST m_hImageList = (HIMAGELIST)DefWindowProc (TB_GETIMAGELIST, 0, 0); TBBUTTON tbbutton; int nCount = DefWindowProc (TB_BUTTONCOUNT, 0, 0); int nHotItem = GetToolBarCtrl().GetHotItem(); for ( int i = 0; i < nCount; i++ ) { VERIFY(DefWindowProc (TB_GETBUTTON, i, (LPARAM)&tbbutton)); if ( !IS_VISIBLE(tbbutton) ) { continue; } CRect rcButton; VERIFY(DefWindowProc (TB_GETITEMRECT, i, (LPARAM)&rcButton)); if ( !CRect().IntersectRect (rcClip, rcButton) ) { continue; } bool bOver = nHotItem == i && IS_ENABLED(tbbutton); bool bPressed = false; if ( IS_INDETERMINATE(tbbutton) ) { CPenDC pen (cDC, ::GetSysColor (COLOR_3DSHADOW)); cDC.MoveTo (rcButton.left, rcButton.bottom); cDC.LineTo (rcButton.left, rcButton.top); cDC.LineTo (rcButton.right-1, rcButton.top); cDC.LineTo (rcButton.right-1, rcButton.bottom-1); cDC.LineTo (rcButton.left, rcButton.bottom-1); bOver = true; } else if ( bOver || IS_CHECKED(tbbutton) ) { bPressed = KEYDOWN(VK_LBUTTON) && rcButton.PtInRect (ptCursor); if ( IS_DROPDOWN(tbbutton) && bPressed ) { bPressed = ptCursor.x < rcButton.right-13; if ( bPressed ) { rcButton.right -= 13; } } COLORREF crHighLight = ::GetSysColor (COLOR_HIGHLIGHT); CPenDC pen (cDC, crHighLight); CBrushDC brush (cDC, bPressed||(bOver&&IS_CHECKED(tbbutton)) ? HLS_TRANSFORM (crHighLight, +50, -50) : (bOver ? HLS_TRANSFORM (crHighLight, +70, -57) : HLS_TRANSFORM (crHighLight, +80, -66))); cDC.Rectangle (&rcButton); if ( IS_DROPDOWN(tbbutton) ) { if ( bPressed ) { int nLeft = rcButton.left; rcButton.left = rcButton.right-1; rcButton.right += 13; brush.Color (HLS_TRANSFORM (crHighLight, +70, -66)); cDC.Rectangle (&rcButton); rcButton.left = nLeft; } else { cDC.MoveTo (rcButton.right-14, rcButton.top); cDC.LineTo (rcButton.right-14, rcButton.bottom); } } } if ( IS_SEPARATOR(tbbutton) ) { CPenDC pen (cDC, HLS_TRANSFORM (::GetSysColor (COLOR_3DFACE), -15, 0)); if ( IS_WRAP(tbbutton) ) { cDC.MoveTo (rcClient.left+2, rcButton.bottom-4); cDC.LineTo (rcClient.right-2, rcButton.bottom-4); } else { cDC.MoveTo ((rcButton.right+rcButton.left)/2-1, rcButton.top+2); cDC.LineTo ((rcButton.right+rcButton.left)/2-1, rcButton.bottom-2); } } else if ( !IS_CONTROL(tbbutton) ) { if ( IS_DROPDOWN(tbbutton) ) { CPenDC pen (cDC, ( bOver && !IS_INDETERMINATE(tbbutton) ) ? RGB(0,0,0) : ::GetSysColor (IS_ENABLED(tbbutton) ? COLOR_BTNTEXT : COLOR_GRAYTEXT)); cDC.MoveTo (rcButton.right-9, (rcButton.top+rcButton.bottom)/2-1); cDC.LineTo (rcButton.right-4, (rcButton.top+rcButton.bottom)/2-1); cDC.MoveTo (rcButton.right-8, (rcButton.top+rcButton.bottom)/2); cDC.LineTo (rcButton.right-5, (rcButton.top+rcButton.bottom)/2); cDC.SetPixel (rcButton.right-7, (rcButton.top+rcButton.bottom)/2+1, pen.Color()); rcButton.right -= 14; } if ( tbbutton.iBitmap >= 0 ) { if ( !IS_ENABLED(tbbutton) || (bOver && !bPressed) ) { HICON hIcon = ImageList_ExtractIcon (NULL, m_hImageList, tbbutton.iBitmap); cDC.DrawState (CPoint (rcButton.left + ( bOver ? 4 : 3 ), rcButton.top + ( bOver ? 4 : 3 )), m_sizeImage, hIcon, DSS_MONO, CBrush (bOver ? (IS_INDETERMINATE(tbbutton) ? HLS_TRANSFORM (::GetSysColor (COLOR_3DFACE), -20, 0) : HLS_TRANSFORM (::GetSysColor (COLOR_HIGHLIGHT), +50, -66)) : HLS_TRANSFORM (::GetSysColor (COLOR_3DFACE), -27, 0))); DestroyIcon (hIcon); } if ( IS_ENABLED(tbbutton) ) { ::ImageList_Draw (m_hImageList, tbbutton.iBitmap, cDC.m_hDC, rcButton.left + ( (bOver && !bPressed) ? 2 : 3 ), rcButton.top + ( (bOver && !bPressed) ? 2 : 3 ), ILD_TRANSPARENT); } } } } }
EXPRESSION expression_generate(char *original) { int i, length, offset; char *string = (char *)malloc(MAX_STRING * sizeof(char)); strcpy(string,original); // remove whitespace offset = 0; length = strlen(string); for(i = 0; i < length; i ++) { if(string[i + offset] == ' ') { offset ++; length --; } string[i] = string[i + offset]; } string[i] = '\0'; // convert multiple expressions into just one length = strlen(string); int n_name, n_expr; char *name = (char *)malloc(MAX_STRING * sizeof(char)); char *expr = (char *)malloc(MAX_STRING * sizeof(char)); char *temp = (char *)malloc(MAX_STRING * sizeof(char)); if(name == NULL || expr == NULL || temp == NULL) return NULL; while(IS_VARIABLE(string[0])) { i = 0; do name[i] = string[i]; while(string[++i] != EQUALITY); n_name = i; name[n_name] = '\0'; i ++; do expr[i - n_name - 1] = string[i]; while(string[++i] != SEPERATOR); n_expr = i - n_name - 1; expr[n_expr] = '\0'; i ++; while(string[i] == ';') i ++; sprintf(temp,"%s",&string[i]); strcpy(string,temp); i = 0; do { if(strncmp(&string[i],name,n_name) == 0 && (!IS_VARIABLE(string[i+n_name]) || string[i+n_name] == '\0')) { string[i] = '\0'; sprintf(temp,"%s%c%s%c%s",string,LEFTBRACE,expr,RIGHTBRACE,&string[i + n_name]); strcpy(string,temp); } i ++; } while(i < strlen(string)); } free(name); free(expr); free(temp); // convert the infix string into lists of postfix/RPN operations length = strlen(string); int o = 0; int *operator = (int *)malloc(MAX_ELEMENTS * sizeof(int)); if(operator == NULL) return NULL; int e = 0; EXPRESSION expression = (EXPRESSION)malloc(MAX_ELEMENTS * sizeof(struct s_EXPRESSION)); if(expression == NULL) return NULL; int index; i = 0; do { if(string[i] == LEFTBRACE) { operator[o++] = LEFTBRACE; i ++; } else if(string[i] == RIGHTBRACE) { while(operator[o-1] != LEFTBRACE) { expression[e++].type = operator[--o]; if(!o) return NULL; } i ++; o --; } else if(IS_OPERATOR(string[i])) { while(o > 0) if(precedence[(int)string[i]] <= precedence[operator[o-1]]) expression[e++].type = operator[--o]; else break; operator[o++] = string[i++]; } else if(IS_VALUE(string[i])) { sscanf(&string[i],"%lf",&expression[e].value); expression[e++].type = VALUE; while((i < length) && ((!IS_OPERATOR(string[i]) && !IS_CONTROL(string[i])) || ((string[i] == MINUS || string[i] == PLUS) && (string[i-(i>0)] == 'e' || string[i-(i>0)] == 'E')))) i ++; } else if(string[i] == SUBSTITUTE) { sscanf(&string[++i],"%i",&index); expression[e++].type = SUBSTITUTE_ZERO + index; while(IS_VALUE(string[i])) i ++; } else return NULL; } while(i < length); while(o) expression[e++].type = operator[--o]; expression[e].type = END; // simplify the expression as much as possible expression_simplify(expression); // clean up and return free(string); free(operator); e = 0; while(expression[e].type != END) e ++; return (EXPRESSION)realloc(expression, (e + 1) * sizeof(struct s_EXPRESSION)); }