// w32dlib - Win32 Dialog Helpers // // Copyright (C) 2005 Ian Cowburn (ianc@noddybox.demon.co.uk) // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation; either version 2 of the License, or // (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // // ------------------------------------------------------------------------- // #include "w32dlib/window.h" #include "w32dlib/dialog.h" #include "w32dlib/control.h" namespace W32DLib { // ------------------------------------------------------------ // Dialog::Dialog() : Window() , m_menuowner(0) { } // ------------------------------------------------------------ // Dialog::~Dialog() { } // ------------------------------------------------------------ // void Dialog::OnInit() { } // ------------------------------------------------------------ // void Dialog::OnClose() { } // ------------------------------------------------------------ // INT_PTR Dialog::ShowModal(HINSTANCE inst, HWND parent) { return ::DialogBoxParam(inst, MAKEINTRESOURCE(ResourceID()), parent, &Window::WindowProc, reinterpret_cast(this)); } // ------------------------------------------------------------ // void Dialog::Close(INT_PTR result) { EndDialog(m_wnd,result); } // ------------------------------------------------------------ // void Dialog::Enable(bool enable) { for(ControlSet::iterator i=m_cset.begin();i!=m_cset.end();++i) { (*i)->Enable(enable); } } // ------------------------------------------------------------ // void Dialog::AddControl(Control *control) { m_cset.push_back(control); } // ------------------------------------------------------------ // void Dialog::SetMenuProc(Window *owner, W32DLibCallback callback) { m_menuowner=owner; m_menuproc=callback; } // ------------------------------------------------------------ // void Dialog::SetData() { for(ControlSet::iterator i=m_cset.begin();i!=m_cset.end();++i) { (*i)->DoDataExchange(true); } } // ------------------------------------------------------------ // void Dialog::GetData() { for(ControlSet::iterator i=m_cset.begin();i!=m_cset.end();++i) { (*i)->DoDataExchange(false); } } // ------------------------------------------------------------ // BOOL Dialog::InstanceProc(HWND wnd, UINT msg, WPARAM wp, LPARAM lp) { BOOL ret=FALSE; WORD lo=LOWORD(wp); bool handled=false; switch(msg) { case WM_INITDIALOG: Window::InstanceProc(wnd,msg,wp,lp); m_wnd=wnd; for(ControlSet::iterator i=m_cset.begin();i!=m_cset.end();++i) { W32DEBUGOUT(MsgName(msg) << " (" << msg << ", " << wp << ", " << lp << ")" << " for resource " << (*i)->ResourceID()); (*i)->ProcessMessage(msg,wp,lp); } OnInit(); ret=TRUE; break; case WM_CLOSE: OnClose(); break; case WM_DESTROY: ret=Window::InstanceProc(wnd,msg,wp,lp); break; // Messages passed onto menus and controls // case WM_COMMAND: // Check for windows and resources in the wp // for(ControlSet::iterator i=m_cset.begin();i!=m_cset.end();++i) { if (lo==(*i)->ResourceID()) { W32DEBUGOUT(MsgName(msg) << " (" << msg << ", " << wp << ", " << lp << ")" << " for resource " << (*i)->ResourceID()); ret=(*i)->ProcessMessage(msg,wp,lp); handled=true; break; } } if (!handled && m_menuowner) { W32DEBUGOUT(MsgName(msg) << " (" << msg << ", " << wp << ", " << lp << ")" << " passed onto MenuProc"); ret=(m_menuowner->*m_menuproc)(msg,wp,lp); } break; default: /* W32DEBUGOUT(MsgName(msg) << " (" << msg << ", " << wp << ", " << lp << ")" << " ignored"); */ break; } return ret; } }; // namespace w32dlib // END OF FILE