| 1 | /* |
|---|
| 2 | ----------------------------------------------------------------------------- |
|---|
| 3 | This source file is part of LEXIExporter |
|---|
| 4 | |
|---|
| 5 | Copyright 2006 NDS Limited |
|---|
| 6 | |
|---|
| 7 | Author(s): |
|---|
| 8 | Mark Folkenberg, |
|---|
| 9 | Bo Krohn |
|---|
| 10 | Lasse Tassing |
|---|
| 11 | |
|---|
| 12 | This program is free software; you can redistribute it and/or modify it under |
|---|
| 13 | the terms of the GNU Lesser General Public License as published by the Free Software |
|---|
| 14 | Foundation; either version 2 of the License, or (at your option) any later |
|---|
| 15 | version. |
|---|
| 16 | |
|---|
| 17 | This program is distributed in the hope that it will be useful, but WITHOUT |
|---|
| 18 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
|---|
| 19 | FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. |
|---|
| 20 | |
|---|
| 21 | You should have received a copy of the GNU Lesser General Public License along with |
|---|
| 22 | this program; if not, write to the Free Software Foundation, Inc., 59 Temple |
|---|
| 23 | Place - Suite 330, Boston, MA 02111-1307, USA, or go to |
|---|
| 24 | http://www.gnu.org/copyleft/lesser.txt. |
|---|
| 25 | ----------------------------------------------------------------------------- |
|---|
| 26 | */ |
|---|
| 27 | |
|---|
| 28 | #include "LexiStdAfx.h" |
|---|
| 29 | #include "LexiMaxExport.h" |
|---|
| 30 | #include "LexiDialogAnimProperties.h" |
|---|
| 31 | #include "LexiExportObject.h" |
|---|
| 32 | |
|---|
| 33 | #include "..\Res\resource.h" |
|---|
| 34 | |
|---|
| 35 | #define _PRINT_DEBUG_INFO_ |
|---|
| 36 | // |
|---|
| 37 | // |
|---|
| 38 | |
|---|
| 39 | CAnimPropertiesDlg::CAnimPropertiesDlg(Window* pParent) : Dialog(IDD_DIALOG_ANIMPROPERTIES, DlgProc, pParent) |
|---|
| 40 | { |
|---|
| 41 | memset(&m_OrgClientRect, 0, sizeof(RECT)); |
|---|
| 42 | m_pMetaCtrl=0; |
|---|
| 43 | m_pObj=0; |
|---|
| 44 | m_pData=0; |
|---|
| 45 | } |
|---|
| 46 | |
|---|
| 47 | CAnimPropertiesDlg::~CAnimPropertiesDlg() |
|---|
| 48 | { |
|---|
| 49 | // Destroy meta windows |
|---|
| 50 | m_pMetaCtrl->Detach(); |
|---|
| 51 | ::DestroyWindow(m_hMetaWnd); |
|---|
| 52 | delete m_pMetaCtrl; |
|---|
| 53 | } |
|---|
| 54 | |
|---|
| 55 | // Initialize controls from object |
|---|
| 56 | void CAnimPropertiesDlg::Init(CDDObject *pMeta, const char *pszDefExt) |
|---|
| 57 | { |
|---|
| 58 | // Hookup data |
|---|
| 59 | m_sDefExt=pszDefExt; |
|---|
| 60 | |
|---|
| 61 | if(!m_pMetaCtrl) |
|---|
| 62 | { |
|---|
| 63 | RECT mainrc; |
|---|
| 64 | GetClientRect(mainrc); |
|---|
| 65 | ClientToScreen(mainrc); |
|---|
| 66 | |
|---|
| 67 | // -- animation list created |
|---|
| 68 | |
|---|
| 69 | RECT childrc; |
|---|
| 70 | |
|---|
| 71 | GetDlgItem(IDC_OBJECT_CHILD)->GetClientRect(childrc); |
|---|
| 72 | GetDlgItem(IDC_OBJECT_CHILD)->ClientToScreen(childrc); |
|---|
| 73 | |
|---|
| 74 | int iChildWidth = childrc.right - childrc.left; |
|---|
| 75 | int iChildHeight = childrc.bottom - childrc.top; |
|---|
| 76 | |
|---|
| 77 | int iChildX = childrc.left - mainrc.left; |
|---|
| 78 | int iChildY = childrc.top - mainrc.top; |
|---|
| 79 | |
|---|
| 80 | m_hMetaWnd = ::CreateWindow("MetaControl", NULL, WS_TABSTOP | WS_CHILD | WS_VISIBLE | WS_CLIPCHILDREN, iChildX, iChildY, iChildWidth, iChildHeight, m_hWnd, NULL, CExporter::m_hInstance, NULL); |
|---|
| 81 | |
|---|
| 82 | m_pMetaCtrl = new GDI::MetaControl; |
|---|
| 83 | m_pMetaCtrl->Attach(m_hMetaWnd); |
|---|
| 84 | m_pMetaCtrl->SetDataNotify(this); |
|---|
| 85 | } |
|---|
| 86 | |
|---|
| 87 | // Setup meta data and object data |
|---|
| 88 | m_pMetaCtrl->CreateFromMeta(pMeta); |
|---|
| 89 | |
|---|
| 90 | // Select default control |
|---|
| 91 | GotoDlgCtrl(IDC_NODE); |
|---|
| 92 | } |
|---|
| 93 | |
|---|
| 94 | void CAnimPropertiesDlg::SetInstance(CDDObject *pData, CExportObject* pObj) |
|---|
| 95 | { |
|---|
| 96 | m_pData=pData; |
|---|
| 97 | m_pObj=pObj; |
|---|
| 98 | |
|---|
| 99 | // Setup defaults |
|---|
| 100 | GetDlgItem(IDC_NAME)->SetWindowText(pData->GetString("Name", "<unnamed>")); |
|---|
| 101 | GetDlgItem(IDC_FILENAME)->SetWindowText(pData->GetString("FileName", "<unknown>")); |
|---|
| 102 | m_SaveSeperate.SetCheck(pData->GetBool("Seperate", false)); |
|---|
| 103 | m_pMetaCtrl->SetData(m_pData); |
|---|
| 104 | } |
|---|
| 105 | |
|---|
| 106 | // |
|---|
| 107 | INT_PTR CALLBACK CAnimPropertiesDlg::DlgProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) |
|---|
| 108 | { |
|---|
| 109 | CAnimPropertiesDlg* pThis = (CAnimPropertiesDlg*)Window::GetMapping(hWnd); |
|---|
| 110 | |
|---|
| 111 | switch(message) |
|---|
| 112 | { |
|---|
| 113 | case WM_INITDIALOG: |
|---|
| 114 | { |
|---|
| 115 | pThis = (CAnimPropertiesDlg*)lParam; |
|---|
| 116 | Window::AddMapping(pThis, hWnd); |
|---|
| 117 | pThis->OnInitDialog(); |
|---|
| 118 | } return 0; |
|---|
| 119 | |
|---|
| 120 | case WM_SIZE: |
|---|
| 121 | { |
|---|
| 122 | pThis->OnSize(); |
|---|
| 123 | } break; |
|---|
| 124 | |
|---|
| 125 | case WM_COMMAND: |
|---|
| 126 | { |
|---|
| 127 | switch(LOWORD(wParam)) |
|---|
| 128 | { |
|---|
| 129 | case IDC_NAME: |
|---|
| 130 | if(HIWORD(wParam)==EN_CHANGE) |
|---|
| 131 | pThis->OnNameChange(); |
|---|
| 132 | break; |
|---|
| 133 | case IDC_FILENAME: |
|---|
| 134 | if(HIWORD(wParam)==EN_CHANGE) |
|---|
| 135 | pThis->OnFileNameChange(); |
|---|
| 136 | break; |
|---|
| 137 | case IDC_BROWSEFILE: |
|---|
| 138 | pThis->BrowseOutput(); |
|---|
| 139 | break; |
|---|
| 140 | } |
|---|
| 141 | } break; |
|---|
| 142 | } |
|---|
| 143 | return 0; |
|---|
| 144 | } |
|---|
| 145 | |
|---|
| 146 | // |
|---|
| 147 | void CAnimPropertiesDlg::OnNameChange() |
|---|
| 148 | { |
|---|
| 149 | std::string sValue=GetDlgItem(IDC_NAME)->GetWindowText(); |
|---|
| 150 | m_pData->SetString("Name", sValue.c_str()); |
|---|
| 151 | } |
|---|
| 152 | |
|---|
| 153 | // |
|---|
| 154 | void CAnimPropertiesDlg::OnFileNameChange() |
|---|
| 155 | { |
|---|
| 156 | std::string sValue=GetDlgItem(IDC_FILENAME)->GetWindowText(); |
|---|
| 157 | m_pData->SetString("FileName", sValue.c_str()); |
|---|
| 158 | } |
|---|
| 159 | |
|---|
| 160 | // |
|---|
| 161 | void CAnimPropertiesDlg::OnChanged(const CDDObject *pInstance, const char *pszKey) |
|---|
| 162 | { |
|---|
| 163 | ::SendMessage(m_hParent, WM_NOTIFY_MESSAGE_ID, 0, 0); |
|---|
| 164 | } |
|---|
| 165 | |
|---|
| 166 | // |
|---|
| 167 | void CAnimPropertiesDlg::OnInitDialog() |
|---|
| 168 | { |
|---|
| 169 | GetClientRect(m_OrgClientRect); |
|---|
| 170 | Bind(IDC_SEPERATEFILE, m_SaveSeperate); |
|---|
| 171 | } |
|---|
| 172 | |
|---|
| 173 | // |
|---|
| 174 | void CAnimPropertiesDlg::OnSize() |
|---|
| 175 | { |
|---|
| 176 | // Check if have initialized dialog |
|---|
| 177 | if(m_OrgClientRect.right==0) return; |
|---|
| 178 | |
|---|
| 179 | RECT rNewMain; |
|---|
| 180 | GetClientRect(rNewMain); |
|---|
| 181 | int iDeltaY=rNewMain.bottom-m_OrgClientRect.bottom; |
|---|
| 182 | int iDeltaX=rNewMain.right-m_OrgClientRect.right; |
|---|
| 183 | |
|---|
| 184 | // Get original client rect in screen coordinates |
|---|
| 185 | RECT rScreenRect; |
|---|
| 186 | memcpy(&rScreenRect, &m_OrgClientRect, sizeof(RECT)); |
|---|
| 187 | ClientToScreen(rScreenRect); |
|---|
| 188 | |
|---|
| 189 | // Begin resize/move of all the controls |
|---|
| 190 | HDWP hdwp=::BeginDeferWindowPos(8); |
|---|
| 191 | |
|---|
| 192 | RECT rTemp; |
|---|
| 193 | Window *pItem; |
|---|
| 194 | m_pMetaCtrl->GetWindowRect(rTemp); |
|---|
| 195 | hdwp=::DeferWindowPos(hdwp, m_pMetaCtrl->m_hWnd, NULL, 0, 0, (rTemp.right-rTemp.left)+iDeltaX, (rTemp.bottom-rTemp.top)+iDeltaY, SWP_NOZORDER|SWP_NOMOVE); |
|---|
| 196 | |
|---|
| 197 | // Resize object property frame |
|---|
| 198 | pItem=GetDlgItem(IDC_GROUPBOX_TITLE); |
|---|
| 199 | pItem->GetWindowRect(rTemp); |
|---|
| 200 | hdwp=::DeferWindowPos(hdwp, pItem->m_hWnd, NULL, 0, 0, (rTemp.right-rTemp.left)+iDeltaX, (rTemp.bottom-rTemp.top)+iDeltaY, SWP_NOZORDER|SWP_NOMOVE); |
|---|
| 201 | |
|---|
| 202 | if(iDeltaX!=0) |
|---|
| 203 | { |
|---|
| 204 | // Move browse filename button |
|---|
| 205 | pItem=GetDlgItem(IDC_BROWSEFILE); |
|---|
| 206 | pItem->GetWindowRect(rTemp); |
|---|
| 207 | ScreenToClient(rTemp); |
|---|
| 208 | hdwp=::DeferWindowPos(hdwp, pItem->m_hWnd, NULL, rTemp.left+iDeltaX, rTemp.top, 0, 0, SWP_NOZORDER|SWP_NOSIZE); |
|---|
| 209 | |
|---|
| 210 | // Resize name window |
|---|
| 211 | pItem=GetDlgItem(IDC_NAME); |
|---|
| 212 | pItem->GetWindowRect(rTemp); |
|---|
| 213 | hdwp=::DeferWindowPos(hdwp, pItem->m_hWnd, NULL, 0, 0, (rTemp.right-rTemp.left)+iDeltaX, (rTemp.bottom-rTemp.top), SWP_NOZORDER|SWP_NOMOVE); |
|---|
| 214 | |
|---|
| 215 | // Resize filename window |
|---|
| 216 | pItem=GetDlgItem(IDC_FILENAME); |
|---|
| 217 | pItem->GetWindowRect(rTemp); |
|---|
| 218 | hdwp=::DeferWindowPos(hdwp, pItem->m_hWnd, NULL, 0, 0, (rTemp.right-rTemp.left)+iDeltaX, (rTemp.bottom-rTemp.top), SWP_NOZORDER|SWP_NOMOVE); |
|---|
| 219 | } |
|---|
| 220 | |
|---|
| 221 | ::EndDeferWindowPos(hdwp); |
|---|
| 222 | memcpy(&m_OrgClientRect, &rNewMain, sizeof(RECT)); |
|---|
| 223 | } |
|---|
| 224 | |
|---|
| 225 | // |
|---|
| 226 | void CAnimPropertiesDlg::BrowseOutput() |
|---|
| 227 | { |
|---|
| 228 | // We need to have a valid instance |
|---|
| 229 | if(!m_pObj || !m_pData) return; |
|---|
| 230 | OPENFILENAME ofn; |
|---|
| 231 | |
|---|
| 232 | // Allocate filename buffer and fill out default |
|---|
| 233 | char *pNameBuffer=new char[_MAX_PATH]; |
|---|
| 234 | std::string sDefault=GetDlgItem(IDC_FILENAME)->GetWindowText(); |
|---|
| 235 | strcpy(pNameBuffer, sDefault.c_str()); |
|---|
| 236 | |
|---|
| 237 | memset(&ofn, 0, sizeof(OPENFILENAME)); |
|---|
| 238 | ofn.lStructSize = sizeof(OPENFILENAME); |
|---|
| 239 | ofn.hwndOwner = m_hWnd; |
|---|
| 240 | ofn.lpstrFilter = m_sDefExt.c_str(); |
|---|
| 241 | ofn.lpstrFile= pNameBuffer; |
|---|
| 242 | ofn.nMaxFile = _MAX_PATH; |
|---|
| 243 | ofn.lpstrInitialDir = (LPSTR)NULL; |
|---|
| 244 | ofn.Flags = OFN_OVERWRITEPROMPT; |
|---|
| 245 | ofn.lpstrTitle = "Save As..."; |
|---|
| 246 | |
|---|
| 247 | if(GetSaveFileName(&ofn)==TRUE) |
|---|
| 248 | { |
|---|
| 249 | GetDlgItem(IDC_FILENAME)->SetWindowText(pNameBuffer); |
|---|
| 250 | } |
|---|
| 251 | } |
|---|