Annotation of mstools/ole20/samples/outline/frametls.c, revision 1.1.1.1

1.1       root        1: /*************************************************************************
                      2: ** 
                      3: **    OLE 2 Server Sample Code
                      4: **    
                      5: **    frametls.c
                      6: **    
                      7: **    This file contains all FrameTools methods and related support
                      8: **    functions. The FrameTools object is an encapsulation of the apps
                      9: **    formula bar and button bar.
                     10: **    
                     11: **    (c) Copyright Microsoft Corp. 1992 - 1993 All Rights Reserved
                     12: **
                     13: *************************************************************************/
                     14: 
                     15: #include "outline.h"
                     16: 
                     17: OLEDBGDATA
                     18: 
                     19: /* private function prototype */
                     20: static void Bar_Move(LPBAR lpbar, LPRECT lprcClient, LPRECT lprcPopup);
                     21: static void FB_ResizeEdit(LPBAR lpbar);
                     22: 
                     23: extern LPOUTLINEAPP g_lpApp;
                     24: extern RECT g_rectNull;
                     25: 
                     26: /* 
                     27:  * FrameToolsRegisterClass
                     28:  *
                     29:  * Purpose:
                     30:  *  Register the popup toolbar window class
                     31:  *
                     32:  * Parameters:
                     33:  *  hInst           Process instance
                     34:  *
                     35:  * Return Value:
                     36:  *  TRUE            if successful
                     37:  *  FALSE           if failed
                     38:  * 
                     39:  */
                     40: BOOL FrameToolsRegisterClass(HINSTANCE hInst)
                     41: {
                     42:     WNDCLASS wc;
                     43:     
                     44:     // Register Tool Palette Class
                     45:     wc.style = CS_BYTEALIGNWINDOW;
                     46:     wc.lpfnWndProc = FrameToolsWndProc;
                     47:     wc.cbClsExtra = 0;
                     48:     wc.cbWndExtra = 4;
                     49:     wc.hInstance = hInst;
                     50:     wc.hIcon = NULL;
                     51:     wc.hCursor = LoadCursor(NULL, IDC_ARROW);
                     52:     wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
                     53:     wc.lpszMenuName = NULL;
                     54:     wc.lpszClassName = CLASS_PALETTE;
                     55: 
                     56:     if (!RegisterClass(&wc))
                     57:         return FALSE;
                     58:     else
                     59:         return TRUE;
                     60: }
                     61: 
                     62: 
                     63: static BOOL FrameTools_CreatePopupPalette(LPFRAMETOOLS lpft, HWND hWndFrame)
                     64: {
                     65:     if (lpft->m_hWndPopupPalette) 
                     66:         DestroyWindow(lpft->m_hWndPopupPalette);
                     67: 
                     68:     lpft->m_hWndPopupPalette = CreateWindow(
                     69:         CLASS_PALETTE,
                     70:         "Tool Palette",
                     71:         WS_POPUP | WS_CAPTION | WS_CLIPCHILDREN,
                     72:         CW_USEDEFAULT, 0, 0, 0,
                     73:         hWndFrame,
                     74:         (HMENU)NULL,
                     75:         g_lpApp->m_hInst,
                     76:         0L
                     77:     );
                     78:     
                     79:     if (!lpft->m_hWndPopupPalette)
                     80:         return FALSE;
                     81:     
                     82:     SetWindowLong(lpft->m_hWndPopupPalette, 0, (LONG)lpft);
                     83:     return TRUE;
                     84: }
                     85: 
                     86: 
                     87: /* 
                     88:  * FrameTools_Init
                     89:  *
                     90:  * Purpose:
                     91:  *  Init and create the toolbar
                     92:  *
                     93:  * Parameters:
                     94:  *  lpft            FrameTools object
                     95:  *  hWndParent      The window which owns the toolbar
                     96:  *  hInst           Process instance
                     97:  *
                     98:  * Return Value:
                     99:  *  TRUE            if successful
                    100:  *  FALSE           if failed
                    101:  * 
                    102:  */
                    103: BOOL FrameTools_Init(LPFRAMETOOLS lpft, HWND hWndParent, HINSTANCE hInst)
                    104: {
                    105:     RECT        rc;
                    106:     UINT        uPos;
                    107:     UINT        dx;
                    108:     UINT        dy;
                    109:     
                    110:     if (!lpft || !hWndParent || !hInst)
                    111:         return FALSE;
                    112: 
                    113:     //Get BTTNCUR's display information
                    114:     UIToolConfigureForDisplay(&lpft->m_tdd);
                    115: 
                    116:     dx=lpft->m_tdd.cxButton;
                    117:     dy=lpft->m_tdd.cyButton;
                    118: 
                    119:     // 15 is calculated from the total number of buttons and separators
                    120:     lpft->m_uPopupWidth = dx * 15;
                    121: 
                    122:     lpft->m_hWndApp = hWndParent;
                    123:     lpft->m_ButtonBar.m_nState = BARSTATE_TOP;
                    124:     lpft->m_FormulaBar.m_nState = BARSTATE_TOP;
                    125:     lpft->m_fInFormulaBar = FALSE;
                    126: 
                    127:     lpft->m_fToolsDisabled = FALSE;
                    128: 
                    129:     lpft->m_ButtonBar.m_uHeight = lpft->m_tdd.cyBar;
                    130:     lpft->m_FormulaBar.m_uHeight = lpft->m_tdd.cyBar;
                    131: 
                    132: 
                    133:     //Get our image bitmaps for the display type we're on
                    134:     if (72 == lpft->m_tdd.uDPI)
                    135:         lpft->m_hBmp = LoadBitmap(hInst, (LPCSTR)"Image72");
                    136:     if (96 == lpft->m_tdd.uDPI)  
                    137:         lpft->m_hBmp = LoadBitmap(hInst, (LPCSTR)"Image96");
                    138:     if (120 == lpft->m_tdd.uDPI) 
                    139:         lpft->m_hBmp = LoadBitmap(hInst, (LPCSTR)"Image120");
                    140: 
                    141:     if (!lpft->m_hBmp)
                    142:         return FALSE;
                    143: 
                    144:     /* Create Popup Tool Palette window */
                    145:     lpft->m_hWndPopupPalette = NULL;
                    146:     if (! FrameTools_CreatePopupPalette(lpft, hWndParent)) 
                    147:         return FALSE;
                    148:     
                    149:     uPos = 0;
                    150:     //Create the GizmoBar and the client area window
                    151:     GetClientRect(hWndParent, &rc);
                    152:     lpft->m_ButtonBar.m_hWnd = CreateWindow(
                    153:         CLASS_GIZMOBAR, 
                    154:         "ButtonBar", 
                    155:         WS_CHILD | WS_VISIBLE, 
                    156:         0, 0, rc.right-rc.left, lpft->m_tdd.cyBar, 
                    157:         hWndParent,
                    158:         (HMENU)IDC_GIZMOBAR,
                    159:         hInst,
                    160:         0L
                    161:     );
                    162: 
                    163:     if (!lpft->m_ButtonBar.m_hWnd)
                    164:         return FALSE;
                    165: 
                    166: 
                    167:     SendMessage(lpft->m_ButtonBar.m_hWnd, WM_SETREDRAW, FALSE, 0L);
                    168: 
                    169:     //File new, open, save, print
                    170:     GBGizmoAdd(lpft->m_ButtonBar.m_hWnd, GIZMOTYPE_BUTTONCOMMAND, uPos++, IDM_F_NEW, dx, dy, NULL, NULL, TOOLIMAGE_FILENEW, GIZMO_NORMAL);
                    171:     GBGizmoAdd(lpft->m_ButtonBar.m_hWnd, GIZMOTYPE_BUTTONCOMMAND, uPos++, IDM_F_OPEN, dx, dy, NULL, NULL, TOOLIMAGE_FILEOPEN, GIZMO_NORMAL);
                    172:     GBGizmoAdd(lpft->m_ButtonBar.m_hWnd, GIZMOTYPE_BUTTONCOMMAND, uPos++, IDM_F_SAVE, dx, dy, NULL, NULL, TOOLIMAGE_FILESAVE, GIZMO_NORMAL);
                    173:     GBGizmoAdd(lpft->m_ButtonBar.m_hWnd, GIZMOTYPE_BUTTONCOMMAND, uPos++, IDM_F_PRINT, dx, dy, NULL, NULL, TOOLIMAGE_FILEPRINT, GIZMO_NORMAL);
                    174:     
                    175:     // separator
                    176:     GBGizmoAdd(lpft->m_ButtonBar.m_hWnd, GIZMOTYPE_SEPARATOR, uPos++, 0, dx/2, dy, NULL, NULL, 0, GIZMO_NORMAL);
                    177: 
                    178:     // Edit cut, copy, paste
                    179:     GBGizmoAdd(lpft->m_ButtonBar.m_hWnd, GIZMOTYPE_BUTTONCOMMAND, uPos++, IDM_E_CUT, dx, dy, NULL, NULL, TOOLIMAGE_EDITCUT, GIZMO_NORMAL);
                    180:     GBGizmoAdd(lpft->m_ButtonBar.m_hWnd, GIZMOTYPE_BUTTONCOMMAND, uPos++, IDM_E_COPY, dx, dy, NULL, NULL, TOOLIMAGE_EDITCOPY, GIZMO_NORMAL);
                    181:     GBGizmoAdd(lpft->m_ButtonBar.m_hWnd, GIZMOTYPE_BUTTONCOMMAND, uPos++, IDM_E_PASTE, dx, dy, NULL, NULL, TOOLIMAGE_EDITPASTE, GIZMO_NORMAL);
                    182: 
                    183:     // separator
                    184:     GBGizmoAdd(lpft->m_ButtonBar.m_hWnd, GIZMOTYPE_SEPARATOR, uPos++, 0, dx/2, dy, NULL, NULL, 0, GIZMO_NORMAL);
                    185:     
                    186:     // Line indent, unindent
                    187:     GBGizmoAdd(lpft->m_ButtonBar.m_hWnd, GIZMOTYPE_BUTTONCOMMAND, uPos++, IDM_L_UNINDENTLINE, dx, dy, NULL, lpft->m_hBmp, IDB_UNINDENTLINE, GIZMO_NORMAL);  
                    188:     GBGizmoAdd(lpft->m_ButtonBar.m_hWnd, GIZMOTYPE_BUTTONCOMMAND, uPos++, IDM_L_INDENTLINE, dx, dy, NULL, lpft->m_hBmp, IDB_INDENTLINE, GIZMO_NORMAL);
                    189:         
                    190:     // separator
                    191:     GBGizmoAdd(lpft->m_ButtonBar.m_hWnd, GIZMOTYPE_SEPARATOR, uPos++, 0, dx/2, dy, NULL, NULL, 0, GIZMO_NORMAL);
                    192:     
                    193:     // Help
                    194:     GBGizmoAdd(lpft->m_ButtonBar.m_hWnd, GIZMOTYPE_BUTTONCOMMAND, uPos++, IDM_H_ABOUT, dx, dy, NULL, NULL, TOOLIMAGE_HELP, GIZMO_NORMAL);
                    195: 
                    196:     SendMessage(lpft->m_ButtonBar.m_hWnd, WM_SETREDRAW, TRUE, 0L);
                    197: 
                    198: 
                    199:     uPos = 0;
                    200:     lpft->m_FormulaBar.m_hWnd = CreateWindow(
                    201:         CLASS_GIZMOBAR, 
                    202:         "FormulaBar", 
                    203:         WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS, 
                    204:         0, lpft->m_tdd.cyBar, rc.right-rc.left, lpft->m_tdd.cyBar, 
                    205:         hWndParent,
                    206:         (HMENU)IDC_FORMULABAR,
                    207:         hInst,
                    208:         0L
                    209:     );
                    210: 
                    211:     if (!lpft->m_FormulaBar.m_hWnd)
                    212:         return FALSE;
                    213: 
                    214:     SendMessage(lpft->m_FormulaBar.m_hWnd, WM_SETREDRAW, FALSE, 0L);
                    215: 
                    216:     // Line add line
                    217:     GBGizmoAdd(lpft->m_FormulaBar.m_hWnd, GIZMOTYPE_BUTTONCOMMAND, uPos++, IDM_L_ADDLINE, dx, dy, NULL, lpft->m_hBmp, IDB_ADDLINE, GIZMO_NORMAL);
                    218: 
                    219:     // separator
                    220:     GBGizmoAdd(lpft->m_FormulaBar.m_hWnd, GIZMOTYPE_SEPARATOR, uPos++, 0, dx/2, dy, NULL, NULL, 0, GIZMO_NORMAL);
                    221: 
                    222:     // Line edit line, Cancel
                    223:     GBGizmoAdd(lpft->m_FormulaBar.m_hWnd, GIZMOTYPE_BUTTONCOMMAND, uPos++, IDM_L_EDITLINE, dx, dy, NULL, lpft->m_hBmp, IDB_EDITLINE, GIZMO_NORMAL);
                    224:     GBGizmoAdd(lpft->m_FormulaBar.m_hWnd, GIZMOTYPE_BUTTONCOMMAND, uPos++, IDM_FB_CANCEL, dx, dy, NULL, lpft->m_hBmp, IDB_CANCEL, GIZMO_NORMAL);
                    225: 
                    226:     // separator
                    227:     GBGizmoAdd(lpft->m_FormulaBar.m_hWnd, GIZMOTYPE_SEPARATOR, uPos++, 0, dx/2, dy, NULL, NULL, 0, GIZMO_NORMAL);
                    228:     
                    229:     // Edit control for line input
                    230:     GBGizmoAdd(lpft->m_FormulaBar.m_hWnd, GIZMOTYPE_EDIT, uPos++, IDM_FB_EDIT, dx*10, lpft->m_tdd.cyBar-5, NULL, NULL, 0, GIZMO_NORMAL);
                    231: 
                    232:     
                    233:     SendMessage(lpft->m_FormulaBar.m_hWnd, WM_SETREDRAW, TRUE, 0L);
                    234: 
                    235:     // Limit the text lenght of edit control
                    236:     GBGizmoSendMessage(lpft->m_FormulaBar.m_hWnd, IDM_FB_EDIT, EM_LIMITTEXT,
                    237:         (WPARAM)MAXSTRLEN, 0L);
                    238: 
                    239:     //Set the GizmoBar's associate to be this client window
                    240:     GBHwndAssociateSet(lpft->m_ButtonBar.m_hWnd, hWndParent);
                    241:         
                    242:     //Set the FormulaBar's associate to be this client window
                    243:     GBHwndAssociateSet(lpft->m_FormulaBar.m_hWnd, hWndParent);
                    244: 
                    245:     return TRUE;
                    246: }
                    247: 
                    248: 
                    249: void FrameTools_AttachToFrame(LPFRAMETOOLS lpft, HWND hWndFrame)
                    250: {
                    251:     if (! lpft) 
                    252:         return;
                    253: 
                    254:     if (hWndFrame == NULL) 
                    255:         hWndFrame = OutlineApp_GetFrameWindow((LPOUTLINEAPP)g_lpApp);
                    256: 
                    257:     if (lpft->m_hWndApp == hWndFrame) 
                    258:         return;     // already have this parent frame
                    259: 
                    260:     lpft->m_hWndApp = hWndFrame;
                    261: 
                    262:     /* parent the tool bars to the frame so we can safely
                    263:     **    destroy/recreate the palette window.
                    264:     */
                    265:     SetParent(lpft->m_ButtonBar.m_hWnd, hWndFrame);
                    266:     SetParent(lpft->m_FormulaBar.m_hWnd, hWndFrame);
                    267: 
                    268:     // recreate popup palette so that it is owned by the hWndFrame
                    269:     FrameTools_CreatePopupPalette(lpft, hWndFrame);
                    270: 
                    271:     // restore the correct parent for the tool bars
                    272:     FrameTools_BB_SetState(lpft, lpft->m_ButtonBar.m_nState);
                    273:     FrameTools_FB_SetState(lpft, lpft->m_FormulaBar.m_nState);
                    274: }   
                    275: 
                    276: 
                    277: void FrameTools_AssociateDoc(LPFRAMETOOLS lpft, LPOUTLINEDOC lpOutlineDoc)
                    278: {
                    279:     HWND hWnd = OutlineDoc_GetWindow(lpOutlineDoc);
                    280: 
                    281:     if (! lpft) 
                    282:         return;
                    283: 
                    284:     // if no Doc is given, then associate with the App's frame window. 
                    285:     if (lpOutlineDoc) 
                    286:         hWnd = OutlineDoc_GetWindow(lpOutlineDoc);
                    287:     else 
                    288:         hWnd = OutlineApp_GetWindow((LPOUTLINEAPP)g_lpApp);
                    289: 
                    290:     //Set the GizmoBar's associate to be this client window
                    291:     GBHwndAssociateSet(lpft->m_ButtonBar.m_hWnd, hWnd);
                    292:         
                    293:     //Set the FormulaBar's associate to be this client window
                    294:     GBHwndAssociateSet(lpft->m_FormulaBar.m_hWnd, hWnd);
                    295: }   
                    296: 
                    297: 
                    298: /* 
                    299:  * FrameTools_Destroy
                    300:  *
                    301:  * Purpose:
                    302:  *  Destroy the toolbar
                    303:  *
                    304:  * Parameters:
                    305:  *  lpft            FrameTools object
                    306:  *
                    307:  * Return Value:
                    308:  *  nil
                    309:  */
                    310: void FrameTools_Destroy(LPFRAMETOOLS lpft)
                    311: {
                    312:     if (!lpft) 
                    313:         return;
                    314: 
                    315:     if (IsWindow(lpft->m_ButtonBar.m_hWnd))
                    316:         DestroyWindow(lpft->m_ButtonBar.m_hWnd);
                    317:     if (IsWindow(lpft->m_FormulaBar.m_hWnd))
                    318:         DestroyWindow(lpft->m_FormulaBar.m_hWnd);
                    319:     if (IsWindow(lpft->m_hWndPopupPalette))
                    320:         DestroyWindow(lpft->m_hWndPopupPalette);
                    321:     
                    322:     if (lpft->m_hBmp)
                    323:         DeleteObject(lpft->m_hBmp);
                    324: }
                    325: 
                    326: 
                    327: /* 
                    328:  * FrameTools_Move
                    329:  *
                    330:  * Purpose:
                    331:  *  Move and resize the toolbar
                    332:  *
                    333:  * Parameters:
                    334:  *  lpft            FrameTools object
                    335:  *  lprc            Pointer to client rectangle
                    336:  *
                    337:  * Return Value:
                    338:  *  nil
                    339:  */
                    340: void FrameTools_Move(LPFRAMETOOLS lpft, LPRECT lprcClient)
                    341: {
                    342:     RECT rcPopup;
                    343:     LPRECT lprcPopup = (LPRECT)&rcPopup;
                    344:     int nCmdShow = SW_HIDE;
                    345:     
                    346:     if (!lpft || lpft->m_fToolsDisabled)
                    347:         return;
                    348: 
                    349:     lprcPopup->left = 0;
                    350:     lprcPopup->top = 0;
                    351:     lprcPopup->right = lpft->m_uPopupWidth;
                    352:     lprcPopup->bottom = lpft->m_ButtonBar.m_uHeight +
                    353:             lpft->m_FormulaBar.m_uHeight;
                    354:     
                    355:     switch (lpft->m_ButtonBar.m_nState) {
                    356:         case BARSTATE_HIDE:
                    357:         case BARSTATE_POPUP:
                    358:         case BARSTATE_TOP:
                    359:             Bar_Move(&lpft->m_ButtonBar, lprcClient, lprcPopup);
                    360:             Bar_Move(&lpft->m_FormulaBar, lprcClient, lprcPopup);
                    361:             break;
                    362:             
                    363:         case BARSTATE_BOTTOM:
                    364:             Bar_Move(&lpft->m_FormulaBar, lprcClient, lprcPopup);
                    365:             Bar_Move(&lpft->m_ButtonBar, lprcClient, lprcPopup);
                    366:             break;
                    367:     }
                    368:     
                    369:     if (lprcPopup->top) {
                    370:         SetWindowPos(lpft->m_hWndPopupPalette, NULL, 0, 0, lprcPopup->right,
                    371:                 lprcPopup->top + GetSystemMetrics(SM_CYCAPTION), 
                    372:                 SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE | SWP_SHOWWINDOW);
                    373:     }
                    374:     else
                    375:         ShowWindow(lpft->m_hWndPopupPalette, SW_HIDE);  
                    376:     
                    377:     FB_ResizeEdit(&lpft->m_FormulaBar);
                    378:     
                    379:     InvalidateRect(lpft->m_ButtonBar.m_hWnd, NULL, TRUE);
                    380:     InvalidateRect(lpft->m_FormulaBar.m_hWnd, NULL, TRUE);
                    381: }
                    382: 
                    383: 
                    384: /* 
                    385:  * FrameTools_PopupTools
                    386:  *
                    387:  * Purpose:
                    388:  *  Put both formula bar and button bar in Popup Window.
                    389:  *
                    390:  * Parameters:
                    391:  *  lpft            FrameTools object
                    392:  *
                    393:  * Return Value:
                    394:  *  nil
                    395:  */
                    396: void FrameTools_PopupTools(LPFRAMETOOLS lpft)
                    397: {
                    398:     if (! lpft) 
                    399:         return;
                    400: 
                    401:     FrameTools_BB_SetState(lpft, BARSTATE_POPUP);
                    402:     FrameTools_FB_SetState(lpft, BARSTATE_POPUP);
                    403:     FrameTools_Move(lpft, NULL);
                    404: }
                    405: 
                    406: 
                    407: /* 
                    408:  * FrameTools_Enable
                    409:  *
                    410:  * Purpose:
                    411:  *  Enable/Disable(hide) all the tools of the toolbar. 
                    412:  *  this will hide both the buttonbar and the 
                    413:  *  formulabar independent of whether they are floating or anchored.
                    414:  *
                    415:  * Parameters:
                    416:  *  lpft            FrameTools object
                    417:  *  fEnable
                    418:  *
                    419:  * Return Value:
                    420:  *  nil
                    421:  */
                    422: void FrameTools_Enable(LPFRAMETOOLS lpft, BOOL fEnable)
                    423: {
                    424:     lpft->m_fToolsDisabled = !fEnable;
                    425:     if (lpft->m_fToolsDisabled) {
                    426:         ShowWindow(lpft->m_hWndPopupPalette, SW_HIDE);
                    427:         ShowWindow(lpft->m_ButtonBar.m_hWnd, SW_HIDE);
                    428:         ShowWindow(lpft->m_FormulaBar.m_hWnd, SW_HIDE);
                    429:     }
                    430: }
                    431: 
                    432: 
                    433: #if defined( INPLACE_CNTR ) || defined( INPLACE_SVR )
                    434: 
                    435: /* 
                    436:  * FrameTools_NegotiateForSpaceAndShow
                    437:  *
                    438:  * Purpose:
                    439:  *  Negotiate for space for the toolbar tools with the given frame window.
                    440:  *  and make them visible.
                    441:  *  Negotiation steps:
                    442:  *     1. try to get enough space at top/bottom of window
                    443:  *     2. float the tools as a palette if space not available
                    444:  *
                    445:  * Parameters:
                    446:  *  lpft            FrameTools object
                    447:  *
                    448:  * Return Value:
                    449:  *  none
                    450:  */
                    451: void FrameTools_NegotiateForSpaceAndShow(
                    452:         LPFRAMETOOLS            lpft, 
                    453:         LPRECT                  lprcFrameRect,
                    454:         LPOLEINPLACEFRAME       lpTopIPFrame
                    455: )
                    456: {
                    457:     BORDERWIDTHS    borderwidths;
                    458:     RECT            rectBorder;
                    459:     HRESULT         hrErr;
                    460: 
                    461:     if (lprcFrameRect) 
                    462:         rectBorder = *lprcFrameRect;
                    463:     else {
                    464:         /* OLE2NOTE: by calling GetBorder, the server can find out the
                    465:         **    size of the frame window. it can use this information to
                    466:         **    make decisions about how to orient/organize it tools (eg.
                    467:         **    if window is taller than wide put tools vertically at
                    468:         **    left edge).
                    469:         */
                    470:         OLEDBG_BEGIN2("IOleInPlaceFrame::GetBorder called\r\n")
                    471:         hrErr = lpTopIPFrame->lpVtbl->GetBorder(
                    472:                 lpTopIPFrame,
                    473:                 (LPRECT)&rectBorder
                    474:         );
                    475:         OLEDBG_END2
                    476:     }  
                    477: 
                    478:     /* Try SetBorderSpace() with the space that you need. If it fails then
                    479:     ** you can negotiate for space and then do the SetBorderSpace().
                    480:     */
                    481:     FrameTools_GetRequiredBorderSpace(lpft,(LPBORDERWIDTHS)&borderwidths);
                    482:     OLEDBG_BEGIN2("IOleInPlaceFrame::SetBorderSpace called\r\n")
                    483:     hrErr = lpTopIPFrame->lpVtbl->SetBorderSpace(
                    484:             lpTopIPFrame,
                    485:             (LPCBORDERWIDTHS)&borderwidths
                    486:     );
                    487:     OLEDBG_END2
                    488: 
                    489: #if defined( LATER )
                    490:     if (hrErr != NOERROR) {
                    491:         /* Frame did not give the toolsspace that we want. So negotiate */
                    492: 
                    493:         // REVIEW: try a different placement of the tools here
                    494:     
                    495:         OLEDBG_BEGIN2("IOleInPlaceFrame::RequestBorderSpace called\r\n")
                    496:         hrErr = lpTopIPFrame->lpVtbl->RequestBorderSpace(
                    497:                 lpTopIPFrame,
                    498:                 (LPCBORDERWIDTHS)&borderwidths
                    499:         );
                    500:         OLEDBG_END2
                    501: 
                    502:         if (hrErr == NOERROR) {
                    503:             OLEDBG_BEGIN2("IOleInPlaceFrame::SetBorderSpace called\r\n")
                    504:             hrErr = lpTopIPFrame->lpVtbl->SetBorderSpace(
                    505:                     lpTopIPFrame,
                    506:                     (LPCBORDERWIDTHS)&borderwidths
                    507:             );
                    508:             OLEDBG_END2
                    509:         }
                    510:     }
                    511: #endif
                    512:     
                    513:     if (hrErr == NOERROR) {
                    514:         FrameTools_Move(lpft, (LPRECT)&rectBorder);   // we got what we wanted
                    515:     } else {
                    516:         /* We did not get tool space, so POP them up. 
                    517:         /* OLE2NOTE: since we are poping up our tools, we MUST inform
                    518:         **    the top in-place frame window that we need NO tool space
                    519:         **    BUT that it should NOT put its own tools up. if we were
                    520:         **    to pass NULL instead of (0,0,0,0), then the container
                    521:         **    would have the option to leave its own tools up.
                    522:         */
                    523:         OLEDBG_BEGIN2("IOleInPlaceFrame::SetBorderSpace(NULL) called\r\n")
                    524:         hrErr = lpTopIPFrame->lpVtbl->SetBorderSpace(
                    525:                 lpTopIPFrame, 
                    526:                 (LPCBORDERWIDTHS)&g_rectNull
                    527:         );
                    528:         OLEDBG_END2
                    529:         FrameTools_PopupTools(lpft);
                    530:     }
                    531: }
                    532: 
                    533: #endif  // INPLACE_CNTR || INPLACE_SVR
                    534: 
                    535: 
                    536: /* 
                    537:  * FrameTools_GetRequiredBorderSpace
                    538:  *
                    539:  * Purpose:
                    540:  *  Calculate the desired space for the toolbar tools.
                    541:  *
                    542:  * Parameters:
                    543:  *  lpft            FrameTools object
                    544:  *  lpBorderWidths  Widths required at top,bottom,left,right
                    545:  *
                    546:  * Return Value:
                    547:  *  nil
                    548:  */
                    549: void FrameTools_GetRequiredBorderSpace(LPFRAMETOOLS lpft, LPBORDERWIDTHS lpBorderWidths)
                    550: {
                    551:     *lpBorderWidths = g_rectNull;
                    552: 
                    553:     switch (lpft->m_ButtonBar.m_nState) {
                    554:         case BARSTATE_TOP:
                    555:             lpBorderWidths->top += lpft->m_ButtonBar.m_uHeight;
                    556:             break;
                    557: 
                    558:         case BARSTATE_BOTTOM:
                    559:             lpBorderWidths->bottom += lpft->m_ButtonBar.m_uHeight;
                    560:             break;
                    561:     }   
                    562: 
                    563:     switch (lpft->m_FormulaBar.m_nState) {
                    564:         case BARSTATE_TOP:
                    565:             lpBorderWidths->top += lpft->m_FormulaBar.m_uHeight;
                    566:             break;
                    567: 
                    568:         case BARSTATE_BOTTOM:
                    569:             lpBorderWidths->bottom += lpft->m_FormulaBar.m_uHeight;
                    570:             break;
                    571:     }   
                    572: }
                    573: 
                    574: 
                    575: 
                    576: /* 
                    577:  * FrameTools_UpdateButtons
                    578:  *
                    579:  * Purpose:
                    580:  *  Enable/disable individual buttons of the toolbar according to the
                    581:  *  state of the app
                    582:  *
                    583:  * Parameters:
                    584:  *  lpft            FrameTools object
                    585:  *
                    586:  * Return Value:
                    587:  *  nil
                    588:  */
                    589: void FrameTools_UpdateButtons(LPFRAMETOOLS lpft, LPOUTLINEDOC lpOutlineDoc)
                    590: {
                    591:     BOOL fEnable;
                    592: 
                    593: #if defined( OLE_VERSION )
                    594:     LPDATAOBJECT lpClipboardDataObj;
                    595:     HRESULT hrErr;
                    596:     LPOLEAPP lpOleApp = (LPOLEAPP)g_lpApp;
                    597:     BOOL bMsgFilterInstalled = (lpOleApp->m_lpMsgFilter != NULL);
                    598: #endif
                    599: 
                    600:     if (!lpft)
                    601:         return;
                    602:     
                    603:     fEnable = (BOOL)OutlineDoc_GetLineCount(lpOutlineDoc);
                    604:  
                    605:     if (lpft->m_FormulaBar.m_nState != BARSTATE_HIDE) {
                    606:         GBGizmoEnable(lpft->m_FormulaBar.m_hWnd, IDM_L_EDITLINE, fEnable);
                    607: 
                    608:         if (! lpft->m_fInFormulaBar) {
                    609:             GBGizmoEnable(lpft->m_FormulaBar.m_hWnd, IDM_L_ADDLINE, FALSE);
                    610:             GBGizmoEnable(lpft->m_FormulaBar.m_hWnd, IDM_FB_CANCEL, FALSE);
                    611:             GBGizmoEnable(lpft->m_FormulaBar.m_hWnd, IDM_L_EDITLINE, FALSE);
                    612:         } else {
                    613:             GBGizmoEnable(lpft->m_FormulaBar.m_hWnd, IDM_L_ADDLINE, TRUE);
                    614:             GBGizmoEnable(lpft->m_FormulaBar.m_hWnd, IDM_FB_CANCEL, TRUE);
                    615:         }
                    616:     }
                    617: 
                    618:     if (lpft->m_ButtonBar.m_nState != BARSTATE_HIDE) 
                    619:     {
                    620:         GBGizmoEnable(lpft->m_ButtonBar.m_hWnd, IDM_E_CUT, fEnable);
                    621:         GBGizmoEnable(lpft->m_ButtonBar.m_hWnd, IDM_E_COPY, fEnable);
                    622:         GBGizmoEnable(lpft->m_ButtonBar.m_hWnd, IDM_L_INDENTLINE, fEnable);
                    623:         GBGizmoEnable(lpft->m_ButtonBar.m_hWnd, IDM_L_UNINDENTLINE, fEnable);
                    624: 
                    625: #if defined( OLE_SERVER )
                    626: 
                    627:         {
                    628:             LPSERVERDOC lpServerDoc = (LPSERVERDOC)lpOutlineDoc;
                    629: 
                    630: #if defined( INPLACE_SVR )
                    631:             fEnable = ((lpServerDoc->m_fUIActive) ? FALSE : TRUE);
                    632: #else 
                    633:             fEnable = (lpOutlineDoc->m_docInitType != DOCTYPE_EMBEDDED);
                    634: #endif  // INPLACE_SVR
                    635:         
                    636:             GBGizmoEnable(lpft->m_ButtonBar.m_hWnd, IDM_F_NEW, fEnable);
                    637:             GBGizmoEnable(lpft->m_ButtonBar.m_hWnd, IDM_F_OPEN, fEnable);
                    638:             GBGizmoEnable(lpft->m_ButtonBar.m_hWnd, IDM_F_SAVE, fEnable);
                    639:         }
                    640: 
                    641: #endif  // OLE_SERVER
                    642: 
                    643: #if defined( OLE_VERSION )
                    644: 
                    645:         /* OLE2NOTE: we do not want to ever give the busy dialog when we
                    646:         **    are trying to enable or disable our tool bar buttons eg. 
                    647:         **    even if the source of data on the clipboard is busy, we do 
                    648:         **    not want put up the busy dialog. thus we will disable the 
                    649:         **    dialog and at the end re-enable it.
                    650:         */
                    651:         if (bMsgFilterInstalled)
                    652:             OleStdMsgFilter_EnableBusyDialog(lpOleApp->m_lpMsgFilter, FALSE);
                    653:         
                    654:         /* OLE2NOTE: perform OLE specific menu initialization.
                    655:         **    the OLE versions use the OleGetClipboard mechanism for
                    656:         **    clipboard handling. thus, they determine if the Paste 
                    657:         **    command should be enabled in an OLE specific manner. 
                    658:         */
                    659:         fEnable = FALSE;
                    660:         hrErr = OleGetClipboard((LPDATAOBJECT FAR*)&lpClipboardDataObj);
                    661: 
                    662:         if (hrErr == NOERROR) {
                    663:             int nFmtEtc;
                    664:         
                    665:             nFmtEtc = OleStdGetPriorityClipboardFormat(
                    666:                     lpClipboardDataObj,
                    667:                     lpOleApp->m_arrPasteEntries,
                    668:                     lpOleApp->m_nPasteEntries
                    669:             );
                    670:         
                    671:             fEnable = (nFmtEtc >= 0);  // there IS a format we like
                    672: 
                    673:             OleStdRelease((LPUNKNOWN)lpClipboardDataObj);
                    674:         }
                    675: 
                    676:         // re-enable the busy dialog
                    677:         if (bMsgFilterInstalled)
                    678:             OleStdMsgFilter_EnableBusyDialog(lpOleApp->m_lpMsgFilter, TRUE);
                    679: 
                    680:         GBGizmoEnable(lpft->m_ButtonBar.m_hWnd, IDM_E_PASTE, fEnable);  
                    681: 
                    682: #else 
                    683: 
                    684:         // Base Outline version uses standard Windows clipboard handling
                    685:         if(IsClipboardFormatAvailable(g_lpApp->m_cfOutline) || 
                    686:                 IsClipboardFormatAvailable(CF_TEXT))
                    687:             GBGizmoEnable(lpft->m_ButtonBar.m_hWnd, IDM_E_PASTE, TRUE);
                    688:         else 
                    689:             GBGizmoEnable(lpft->m_ButtonBar.m_hWnd, IDM_E_PASTE, FALSE);
                    690: 
                    691: #endif  // OLE_VERSION
                    692: 
                    693:     }  
                    694: }
                    695: 
                    696: /* 
                    697:  * FrameTools_FB_SetEditText
                    698:  *
                    699:  * Purpose:
                    700:  *  Set text in the edit control in FormulaBar
                    701:  *
                    702:  * Parameters:
                    703:  *  lpft            FrameTools object
                    704:  *  lpsz            pointer to string to be set
                    705:  *
                    706:  * Return Value:
                    707:  *  nil
                    708:  */
                    709: void FrameTools_FB_SetEditText(LPFRAMETOOLS lpft, LPSTR lpsz)
                    710: {
                    711:     GBGizmoTextSet(lpft->m_FormulaBar.m_hWnd, IDM_FB_EDIT, lpsz);
                    712: }
                    713: 
                    714: 
                    715: /* 
                    716:  * FrameTools_FB_GetEditText
                    717:  *
                    718:  * Purpose:
                    719:  *  Get text from the edit control in FormulaBar
                    720:  *
                    721:  * Parameters:
                    722:  *  lpft            FrameTools object
                    723:  *  lpsz            pointer to buffer to receive the text
                    724:  *  cch             buffer size
                    725:  *
                    726:  * Return Value:
                    727:  *  nil
                    728:  */
                    729: void FrameTools_FB_GetEditText(LPFRAMETOOLS lpft, LPSTR lpsz, UINT cch)
                    730: {
                    731:     GBGizmoTextGet(lpft->m_FormulaBar.m_hWnd, IDM_FB_EDIT, lpsz, cch);
                    732: }
                    733: 
                    734: 
                    735: /* 
                    736:  * FrameTools_FB_FocusEdit
                    737:  *
                    738:  * Purpose:
                    739:  *  Set the focus in the edit control of FormulaBar
                    740:  *
                    741:  * Parameters:
                    742:  *  lpft            FrameTools object
                    743:  *
                    744:  * Return Value:
                    745:  *  nil
                    746:  */
                    747: void FrameTools_FB_FocusEdit(LPFRAMETOOLS lpft)
                    748: {
                    749:     GBGizmoFocusSet(lpft->m_FormulaBar.m_hWnd, IDM_FB_EDIT);
                    750:     
                    751:     // select the whole text in the edit control
                    752:     GBGizmoSendMessage(lpft->m_FormulaBar.m_hWnd, IDM_FB_EDIT, EM_SETSEL, 
                    753:             (WPARAM)TRUE, MAKELPARAM(0, -1));
                    754: }
                    755: 
                    756: 
                    757: /* 
                    758:  * FrameTools_FB_SendMessage
                    759:  *
                    760:  * Purpose:
                    761:  *  Send a message to the FormulaBar window gizmo
                    762:  *
                    763:  * Parameters:
                    764:  *  lpft            FrameTools object
                    765:  *  uID             gizmo ID
                    766:  *  msg
                    767:  *  wParam
                    768:  *  lParam  
                    769:  *
                    770:  * Return Value:
                    771:  *  nil
                    772:  */
                    773: void FrameTools_FB_SendMessage(LPFRAMETOOLS lpft, UINT uID, UINT msg, WPARAM wParam, LPARAM lParam)
                    774: {
                    775:     GBGizmoSendMessage(lpft->m_FormulaBar.m_hWnd, uID, msg, wParam, lParam);
                    776: }
                    777: 
                    778: 
                    779: /* 
                    780:  * FrameTools_FB_ForceRedraw
                    781:  *
                    782:  * Purpose:
                    783:  *  Force the toolbar to draw itself
                    784:  *
                    785:  * Parameters:
                    786:  *  lpft            FrameTools object
                    787:  *
                    788:  * Return Value:
                    789:  *  nil
                    790:  */
                    791: void FrameTools_ForceRedraw(LPFRAMETOOLS lpft)
                    792: {
                    793:     InvalidateRect(lpft->m_ButtonBar.m_hWnd, NULL, TRUE);       
                    794:     InvalidateRect(lpft->m_FormulaBar.m_hWnd, NULL, TRUE);
                    795:     InvalidateRect(lpft->m_hWndPopupPalette, NULL, TRUE);
                    796: }
                    797: 
                    798: 
                    799: /* 
                    800:  * FrameTools_BB_SetState
                    801:  *
                    802:  * Purpose:
                    803:  *  Set display state of ButtonBar
                    804:  *
                    805:  * Parameters:
                    806:  *  lpft            FrameTools object
                    807:  *  nState          new display state
                    808:  *
                    809:  * Return Value:
                    810:  *  nil
                    811:  */
                    812: void FrameTools_BB_SetState(LPFRAMETOOLS lpft, int nState)
                    813: {
                    814:     if (!lpft) {
                    815:         return;
                    816:     }
                    817:     
                    818:     lpft->m_ButtonBar.m_nState = nState;
                    819:     
                    820:     if (nState == BARSTATE_POPUP)
                    821:         SetParent(lpft->m_ButtonBar.m_hWnd, lpft->m_hWndPopupPalette);
                    822:     else
                    823:         SetParent(lpft->m_ButtonBar.m_hWnd, lpft->m_hWndApp);
                    824: }
                    825: 
                    826: 
                    827: /* 
                    828:  * FrameTools_BB_GetState
                    829:  *
                    830:  * Purpose:
                    831:  *  Get display state of ButtonBar
                    832:  *
                    833:  * Parameters:
                    834:  *  lpft            FrameTools object
                    835:  *
                    836:  * Return Value:
                    837:  *  nState          current display state
                    838:  */
                    839: int FrameTools_BB_GetState(LPFRAMETOOLS lpft)
                    840: {
                    841:     return lpft->m_ButtonBar.m_nState;
                    842: }
                    843: 
                    844: 
                    845: /* 
                    846:  * FrameTools_FB_SetState
                    847:  *
                    848:  * Purpose:
                    849:  *  Set display state of FormulaBar
                    850:  *
                    851:  * Parameters:
                    852:  *  lpft            FrameTools object
                    853:  *  nState          new display state
                    854:  *
                    855:  * Return Value:
                    856: 4 *  nil
                    857:  */
                    858: void FrameTools_FB_SetState(LPFRAMETOOLS lpft, int nState)
                    859: {
                    860:     if (!lpft) {
                    861:         return;
                    862:     }
                    863:     
                    864:     lpft->m_FormulaBar.m_nState = nState;
                    865: 
                    866:     if (nState == BARSTATE_POPUP)
                    867:         SetParent(lpft->m_FormulaBar.m_hWnd, lpft->m_hWndPopupPalette);
                    868: 
                    869: #if defined( INPLACE_SVR )
                    870:     /* OLE2NOTE: it is dangerous for an in-place server to hide its
                    871:     **    toolbar window and leave it parented to the hWndFrame of the
                    872:     **    in-place container. if the in-place container call
                    873:     **    ShowOwnedPopups, then it could inadvertantly be made visible.
                    874:     **    to avoid this we will parent the toolbar window back to our
                    875:     **    own application main window. if we are not in-place active
                    876:     **    then this is the same as lpft->m_hWndApp.
                    877:     */
                    878:     else if (nState == BARSTATE_HIDE)
                    879:         SetParent(lpft->m_FormulaBar.m_hWnd, g_lpApp->m_hWndApp);
                    880: #endif
                    881: 
                    882:     else
                    883:         SetParent(lpft->m_FormulaBar.m_hWnd, lpft->m_hWndApp);
                    884: }
                    885: 
                    886: 
                    887: /* 
                    888:  * FrameTools_FB_GetState
                    889:  *
                    890:  * Purpose:
                    891:  *  Get display state of FormulaBar
                    892:  *
                    893:  * Parameters:
                    894:  *  lpft            FrameTools object
                    895:  *
                    896:  * Return Value:
                    897:  *  nState          current display state
                    898:  */
                    899: int FrameTools_FB_GetState(LPFRAMETOOLS lpft)
                    900: {
                    901:     return lpft->m_FormulaBar.m_nState;
                    902: }
                    903: 
                    904: 
                    905: /* 
                    906:  * FrameToolsWndProc
                    907:  *
                    908:  * Purpose:
                    909:  *  WndProc for toolbar window
                    910:  *
                    911:  * Parameters:
                    912:  *  hWnd
                    913:  *  Message
                    914:  *  wParam
                    915:  *  lParam
                    916:  *
                    917:  * Return Value:
                    918:  *  message dependent
                    919:  */
                    920: LRESULT FAR PASCAL FrameToolsWndProc(HWND hWnd, UINT Message, WPARAM wParam, LPARAM lParam)
                    921: {
                    922:     LPFRAMETOOLS lpft = (LPFRAMETOOLS)GetWindowLong(hWnd, 0);
                    923:     
                    924:     switch (Message) {
                    925:         
                    926:         case WM_MOUSEACTIVATE:
                    927:             return MA_NOACTIVATE;
                    928: 
                    929:         default:
                    930:             return DefWindowProc(hWnd, Message, wParam, lParam);
                    931:     }
                    932:     
                    933:     return 0L;
                    934: }
                    935:     
                    936: 
                    937: /* 
                    938:  * Bar_Move
                    939:  *
                    940:  * Purpose:
                    941:  *  Resize and reposition a bar
                    942:  *
                    943:  * Parameters:
                    944:  *  lpbar           Bar object
                    945:  *  lprcClient      pointer to Client rect
                    946:  *  lprcPopup       pointer to Popup rect
                    947:  *
                    948:  * Return Value:
                    949:  *  nil
                    950:  */
                    951: static void Bar_Move(LPBAR lpbar, LPRECT lprcClient, LPRECT lprcPopup)
                    952: {
                    953:     if (lpbar->m_nState == BARSTATE_HIDE) {
                    954:         ShowWindow(lpbar->m_hWnd, SW_HIDE);
                    955:     }
                    956:     else {
                    957:         ShowWindow(lpbar->m_hWnd, SW_SHOW);
                    958:         switch (lpbar->m_nState) {
                    959:             case BARSTATE_POPUP:
                    960:                 MoveWindow(lpbar->m_hWnd, lprcPopup->left, lprcPopup->top, 
                    961:                         lprcPopup->right - lprcPopup->left, lpbar->m_uHeight, 
                    962:                         TRUE);
                    963:                 lprcPopup->top += lpbar->m_uHeight;
                    964:                 break;
                    965: 
                    966:             case BARSTATE_TOP:
                    967:                 MoveWindow(lpbar->m_hWnd, lprcClient->left, lprcClient->top, 
                    968:                         lprcClient->right - lprcClient->left, 
                    969:                         lpbar->m_uHeight, TRUE);
                    970:                 lprcClient->top += lpbar->m_uHeight;
                    971:                 break;
                    972: 
                    973:             case BARSTATE_BOTTOM:
                    974:                 MoveWindow(lpbar->m_hWnd, lprcClient->left, 
                    975:                         lprcClient->bottom - lpbar->m_uHeight, 
                    976:                         lprcClient->right - lprcClient->left, 
                    977:                         lpbar->m_uHeight, TRUE);
                    978:                 lprcClient->bottom -= lpbar->m_uHeight;
                    979:                 break;
                    980:         }
                    981:     }
                    982: }
                    983:             
                    984: 
                    985: /* 
                    986:  * FB_ResizeEdit
                    987:  *
                    988:  * Purpose:
                    989:  *  Resize the edit control in FormulaBar
                    990:  *
                    991:  * Parameters:
                    992:  *  lpft            Bar object
                    993:  *
                    994:  * Return Value:
                    995:  *  nil
                    996:  */
                    997: static void FB_ResizeEdit(LPBAR lpbar)
                    998: {
                    999:     RECT rcClient;
                   1000:     RECT rcEdit;
                   1001:     HWND hwndEdit;
                   1002:     
                   1003:     GetClientRect(lpbar->m_hWnd, (LPRECT)&rcClient);
                   1004:     hwndEdit = GetDlgItem(lpbar->m_hWnd, IDM_FB_EDIT);
                   1005:     GetWindowRect(hwndEdit, (LPRECT)&rcEdit);
                   1006:     ScreenToClient(lpbar->m_hWnd, (LPPOINT)&rcEdit.left);
                   1007:     ScreenToClient(lpbar->m_hWnd, (LPPOINT)&rcEdit.right);
                   1008:     
                   1009:     SetWindowPos(hwndEdit, NULL, 0, 0, rcClient.right - rcEdit.left - SPACE,
                   1010:             rcEdit.bottom - rcEdit.top, SWP_NOMOVE | SWP_NOZORDER);
                   1011: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.