GME  13
ModelPropertiesDlgBar.cpp
Go to the documentation of this file.
00001 // ModelPropertiesDlgBar.cpp : implementation file
00002 //
00003 
00004 #include "stdafx.h"
00005 //#include "GMEApp.h"
00006 #include "ModelPropertiesDlgBar.h"
00007 #include "GMEViewStd.h"
00008 
00009 #ifdef _DEBUG
00010 #define new DEBUG_NEW
00011 #undef THIS_FILE
00012 static char THIS_FILE[] = __FILE__;
00013 #endif
00014 
00016 // CModelPropertiesDlgBar dialog
00017 
00018 CModelPropertiesDlgBar::CModelPropertiesDlgBar()
00019         : CDialogBar()
00020 {
00021 }
00022 
00023 BEGIN_MESSAGE_MAP(CModelPropertiesDlgBar, CDialogBar)
00024         ON_CBN_SELENDOK(IDC_ZOOMS, OnSelEnd)
00025         ON_COMMAND(IDOK, OnOK)
00026 END_MESSAGE_MAP()
00027 
00028 void CModelPropertiesDlgBar::ShowType()
00029 {
00030         GetDlgItem(IDC_TYPEMARK)->MoveWindow(6, 8, 16, 16);
00031         GetDlgItem(IDC_TYPEMARK)->ShowWindow(SW_SHOW);
00032         GetDlgItem(IDC_INSTANCEMARK)->ShowWindow(SW_HIDE);
00033         GetDlgItem(IDC_BASETYPE_LABEL)->SetWindowText("Base:");
00034 }
00035 
00036 void CModelPropertiesDlgBar::ShowInstance()
00037 {
00038         GetDlgItem(IDC_TYPEMARK)->ShowWindow(SW_HIDE);
00039         GetDlgItem(IDC_INSTANCEMARK)->MoveWindow(6, 8, 16, 16);
00040         GetDlgItem(IDC_INSTANCEMARK)->ShowWindow(SW_SHOW);
00041         GetDlgItem(IDC_BASETYPE_LABEL)->SetWindowText("Type:");
00042 }
00043 
00045 // CModelPropertiesDlgBar message handlers
00046 
00047 void CModelPropertiesDlgBar::WriteNumToEdit(CEdit *edit, int kk)
00048 {
00049         if (!edit) {
00050                 CWnd* zoom = GetDlgItem(IDC_ZOOMS);
00051                 edit = (CEdit*)(zoom->GetDlgItem(IDC_TYPENAME));
00052         }
00053         char buff[100];
00054         edit->SetSel(0, -1);
00055         itoa(kk, buff, 10);
00056         CString str = buff;
00057         str += "%";
00058         edit->ReplaceSel(str);
00059 }
00060 
00061 void CModelPropertiesDlgBar::OnOK()
00062 {
00063         // enter pressed on which item
00064         CWnd* fwin = GetFocus();
00065         if (!fwin)
00066                 return;
00067         CWnd* zoom = GetDlgItem(IDC_ZOOMS);
00068         if (!zoom)
00069                 return;
00070         CEdit* edit = (CEdit*)(zoom->GetDlgItem(IDC_TYPENAME));
00071         if (!edit)
00072                 return;
00073         if (fwin->m_hWnd == edit->m_hWnd) {
00074                 char buff[100];
00075                 edit->GetLine(0, buff, sizeof(buff) - 1);
00076                 int kk = atoi(buff);
00077                 kk = abs(kk);
00078                 if (!kk)
00079                         kk = 100;
00080                 // send message to zoom with (userdefined=true, kk)
00081                 ((CFrameWnd*)GetParent())->GetActiveView()->PostMessage(WM_USER_ZOOM, (WPARAM)TRUE, (LPARAM)kk);
00082                 WriteNumToEdit(edit, kk);
00083         }
00084         ((CFrameWnd*)GetParent())->GetActiveView()->SetFocus();
00085 }
00086 
00087 
00088 void CModelPropertiesDlgBar::OnSelEnd()
00089 {
00090         // item chosen from list -> zoom 
00091         CComboBox* zoom = (CComboBox*)GetDlgItem(IDC_ZOOMS);
00092         int item = zoom->GetCurSel();
00093         if (item != CB_ERR) {
00094                 int kk = m_zoomlist[item];
00095                 // send message to zoom with (userdefined=false, kk)
00096                 ((CFrameWnd*)GetParent())->GetActiveView()->PostMessage(WM_USER_ZOOM, (WPARAM)FALSE, (LPARAM)kk);
00097         }
00098         ((CFrameWnd*)GetParent())->GetActiveView()->SetFocus();
00099 }
00100 
00101 void CModelPropertiesDlgBar::SetZoomList(int *list)
00102 {
00103         // supposed it is sorted
00104         if (!list)
00105                 return;
00106         for (int i = 0; list[i] && i < MAX_ZOOM - 1; i++) {
00107                 m_zoomlist[i] = list[i];
00108         }
00109         m_zoomlist[i] = 0;
00110         CComboBox* zoom = (CComboBox*)GetDlgItem(IDC_ZOOMS);
00111         for (int k = 0; m_zoomlist[k]; k++) {
00112                 CString str;
00113                 if (m_zoomlist[k] > 0) {
00114                         char buff[100];
00115                         itoa(m_zoomlist[k], buff, 10);
00116                         str = buff;
00117                         str += "%";
00118                 } else {
00119                         switch (m_zoomlist[k]) {
00120                                 case ZOOM_WIDTH:
00121                                         str = "Fit Width";
00122                                         break;
00123                                 case ZOOM_HEIGHT:
00124                                         str = "Fit Height";
00125                                         break;
00126                                 case ZOOM_ALL:
00127                                         str = "Fit All";
00128                                         break;
00129                         }
00130                 }
00131                 zoom->AddString(str);
00132         }
00133 }
00134 
00135 void CModelPropertiesDlgBar::SetZoomVal(int kk)
00136 {
00137         // only to the edit box
00138         if (kk <= 0)
00139                 return;
00140         WriteNumToEdit(NULL, kk);
00141 }
00142 
00143 void CModelPropertiesDlgBar::NextZoomVal(int &kk)
00144 {
00145         // related to the current one in the edit box 
00146         CComboBox* zoom = (CComboBox*)GetDlgItem(IDC_ZOOMS);
00147         if (!zoom)
00148                 return;
00149         CEdit* edit = (CEdit*)(zoom->GetDlgItem(IDC_TYPENAME));
00150         if (!edit)
00151                 return;
00152         char buff[100];
00153         edit->GetLine(0, buff, sizeof(buff) - 1);
00154         kk = atoi(buff);
00155         if (!kk)
00156                 kk = 100;
00157         for (int i = 0; m_zoomlist[i] && m_zoomlist[i] <= kk; i++);
00158         if (m_zoomlist[i]) {
00159                 kk = m_zoomlist[i];
00160                 WriteNumToEdit(edit, kk);
00161         }
00162 }
00163 
00164 void CModelPropertiesDlgBar::PrevZoomVal(int &kk)
00165 {
00166         // related to the current one in the edit box 
00167         CComboBox* zoom = (CComboBox*)GetDlgItem(IDC_ZOOMS);
00168         if (!zoom)
00169                 return;
00170         CEdit* edit = (CEdit*)(zoom->GetDlgItem(IDC_TYPENAME));
00171         if (!edit)
00172                 return;
00173         char buff[100];
00174         edit->GetLine(0, buff, sizeof(buff) - 1);
00175         kk = atoi(buff);
00176         if (!kk)
00177                 kk = 100;
00178         for (int i = 0; m_zoomlist[i] && m_zoomlist[i] < kk; i++);
00179         if (m_zoomlist[i] && i) {
00180                 kk = m_zoomlist[i - 1];
00181                 WriteNumToEdit(edit, kk);
00182         }
00183 }
00184