home *** CD-ROM | disk | FTP | other *** search
/ PC Elektro 3 / PC-Elektro-3-cd1.bin / KBan 2.0 / KBANSRC.LZH / SRC / PROG / KBANTBAR.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1997-09-27  |  2.7 KB  |  97 lines

  1. // the implementation of class CKBANToolBar
  2. // Copyright (C) 1997 Kazutaka Hirata <khirata@jove.acs.unt.edu>
  3.  
  4. #include "stdafx.h"
  5.  
  6. #include "kbandoc.h"
  7. #include "kbanview.h"
  8. #include "resource.h"
  9.  
  10. #include "kbantbar.h"
  11.  
  12. BEGIN_MESSAGE_MAP(CKBANToolBar, CToolBar)
  13.   ON_WM_CREATE()
  14.   ON_CBN_SELENDOK(IDC_LAYERS, OnSelectLayer)
  15.   ON_CBN_CLOSEUP (IDC_LAYERS, OnCloseUp    )
  16. END_MESSAGE_MAP()
  17.  
  18. int CKBANToolBar::OnCreate(LPCREATESTRUCT lpcs)
  19. {
  20.   if(CToolBar::OnCreate(lpcs) == -1) {
  21.     return -1;
  22.   }
  23.   if(!LoadToolBar(IDR_TOOLBAR)) {
  24.     return -1;
  25.   }
  26.  
  27.   CClientDC dc(this);
  28.   int nHeight = -((dc.GetDeviceCaps(LOGPIXELSY) * 8) / 72);
  29.   m_font.CreateFont(nHeight, 0, 0, 0, FW_NORMAL, 0, 0, 0,
  30.     DEFAULT_CHARSET, OUT_CHARACTER_PRECIS, CLIP_CHARACTER_PRECIS,
  31.     DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE, "MS Sans Serif"
  32.   );
  33.   CFont* pOldFont = dc.SelectObject(&m_font);
  34.  
  35.   TEXTMETRIC tm;
  36.   dc.GetTextMetrics(&tm);
  37.   int cxChar = tm.tmAveCharWidth;
  38.   int cyChar = tm.tmHeight + tm.tmExternalLeading;
  39.  
  40.   dc.SelectObject(pOldFont);
  41.  
  42.   const int LayerPos = 17;
  43.  
  44.   // SetHeight(80 + 15 + 6);
  45.   SetButtonInfo(LayerPos, IDC_LAYERS, TBBS_SEPARATOR, cxChar * 22);
  46.  
  47.   CRect rect;
  48.   GetItemRect(LayerPos, &rect);
  49.   rect.bottom = rect.top + cyChar * 16;
  50.  
  51.   if(!m_ctlLayerComboBox.Create(WS_CHILD | WS_VISIBLE | WS_VSCROLL |
  52.     CBS_DROPDOWNLIST, rect, this, IDC_LAYERS)) {
  53.     return -1;
  54.   }
  55.  
  56.   m_ctlLayerComboBox.SetFont(&m_font);
  57.  
  58.   m_ctlLayerComboBox.AddString("Pattern Common");
  59.   m_ctlLayerComboBox.AddString("Pattern Top");
  60.   m_ctlLayerComboBox.AddString("Pattern Bottom");
  61.   m_ctlLayerComboBox.AddString("Silk Top");
  62.   m_ctlLayerComboBox.AddString("Silk Bottom");
  63.  
  64.   return 0;
  65. }
  66.  
  67. void CKBANToolBar::OnSelectLayer(void)
  68. {
  69.   int nIndex = m_ctlLayerComboBox.GetCurSel();
  70.   CKBANView* pView = (CKBANView*)((CFrameWnd*)AfxGetMainWnd())->GetActiveView();
  71.   switch(nIndex) {
  72.     case 0 : pView->OnChangeLayer(ID_LAYER_PCOMMON); break;
  73.     case 1 : pView->OnChangeLayer(ID_LAYER_PTOP   ); break;
  74.     case 2 : pView->OnChangeLayer(ID_LAYER_PBOTTOM); break;
  75.     case 3 : pView->OnChangeLayer(ID_LAYER_STOP   ); break;
  76.     case 4 : pView->OnChangeLayer(ID_LAYER_SBOTTOM); break;
  77.   }
  78. }
  79.  
  80. void CKBANToolBar::OnCloseUp(void)
  81. {
  82.   ((CFrameWnd*)AfxGetMainWnd())->GetActiveView()->SetFocus();
  83. }
  84.  
  85. void CKBANToolBar::OnUpdateCmdUI(CFrameWnd* pTarget, BOOL bDisableIfNoHandler)
  86. {
  87.   CToolBar::OnUpdateCmdUI(pTarget, bDisableIfNoHandler);
  88.  
  89.   CWnd* pWnd = GetFocus();
  90.   if(pWnd != &m_ctlLayerComboBox) {
  91.     CKBANView* pView = (CKBANView*)((CFrameWnd*)AfxGetMainWnd())->GetActiveView();
  92.     KBAN_INFO& info = pView->GetDocument()->kban_info();
  93.     uint layer = info.active_layer().get();
  94.     m_ctlLayerComboBox.SetCurSel(layer);
  95.   }
  96. }
  97.