aswang  1.0
Dialog.cpp
Go to the documentation of this file.
00001 /*
00002         Copyright 2003 Joseph Alvis
00003 
00004     This file is part of Aswang.
00005 
00006     Aswang is free software: you can redistribute it and/or modify
00007     it under the terms of the GNU Lesser General Public License as published by
00008     the Free Software Foundation, either version 3 of the License, or
00009     (at your option) any later version.
00010 
00011     Aswang is distributed in the hope that it will be useful,
00012     but WITHOUT ANY WARRANTY; without even the implied warranty of
00013     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014     GNU Lesser General Public License for more details.
00015 
00016     You should have received a copy of the GNU Lesser General Public License
00017     along with Aswang.  If not, see <http://www.gnu.org/licenses/>.
00018 */
00019 
00020 #include "Dialog.h"
00021 
00022 using namespace aswang;
00023 
00024 void Dialog::Create(int x,int y,int width,int height) {
00025         Create();
00026         Move(x,y);
00027         Resize(width,height);
00028 }
00029 
00030 void Dialog::Create() {
00031         if(!hWnd) {
00032                 if(modeless) {
00033                         CreateDialogParam(hInstance,MAKEINTRESOURCE(tid),((mParent!=NULL)?(HWND)(*mParent):NULL),(DLGPROC)WProc,reinterpret_cast<LPARAM>(this));
00034                 }
00035                 else {
00036                         DialogBoxParam(hInstance,MAKEINTRESOURCE(tid),((mParent!=NULL)?(HWND)(*mParent):NULL),(DLGPROC)WProc,(LPARAM)this);
00037                 }
00038         }
00039 }
00040 
00041 LRESULT Dialog::OnFail(UINT msg,WPARAM wParam,LPARAM lParam) {
00042         return FALSE;
00043 }
00044 
00045 LRESULT Dialog::OnClose() {
00046         if(hWnd) {
00047                 if(modeless) {
00048                         DestroyWindow(hWnd);
00049                 }
00050                 else {
00051                         EndDialog(hWnd,0);
00052                 }
00053                 return TRUE;
00054         }
00055         return FALSE;
00056 }
00057 
00058 LRESULT Dialog::OnInitDialog(HWND win,unsigned long param) {
00059         childMap_type::iterator it;
00060         for(it=childMap.begin();it!=childMap.end();it++) {
00061                 it->second->SetHwnd(GetItem(it->first));
00062                 it->second->Add();
00063         }
00064         return TRUE;
00065 }
00066 
00067 HWND Dialog::GetItem(unsigned long id) {
00068         if(hWnd)
00069                 return GetDlgItem(hWnd,id);
00070         return NULL;
00071 }
00072 
00073 AswangStr Dialog::GetItemText(unsigned long id,unsigned long maxLength) {
00074         _TCHAR *buf = new _TCHAR[maxLength];
00075         AswangStr retstr;
00076         buf[0]=0;
00077         GetDlgItemText(hWnd,id,buf,maxLength);
00078         retstr = buf;
00079         delete buf;
00080         return retstr;
00081 }
00082 
00083 void Dialog::SetItemText(unsigned long id,AswangStr txt) {
00084         SetDlgItemText(hWnd,id,txt.c_str());
00085 }
00086 
00087 LRESULT Dialog::SendItemMessage(unsigned long id,unsigned long message,WPARAM wParam,LPARAM lParam) {
00088         return SendDlgItemMessage(hWnd,id,message,wParam,lParam);
00089 }
00090 
00091 HWND Dialog::operator [] (unsigned long id) {
00092         if(hWnd)
00093                 return GetDlgItem(hWnd,id);
00094         return NULL;
00095 }
00096 
00097 int Dialog::Loop() {
00098         MSG msg;
00099         while(GetMessage(&msg,NULL,0,0) > 0) {
00100                 if(!DispatchDialogMessage(msg)) {
00101                         TranslateMessage(&msg);
00102                         DispatchMessage(&msg);
00103                 }
00104         }
00105         return (int)msg.wParam;
00106 }
00107 
00108 bool Dialog::DispatchDialogMessage(MSG &msg) {
00109         wmap_type::iterator it;
00110         HWND hParent = GetAncestor(msg.hwnd,GA_PARENT);
00111         if(hParent!=0) {
00112                 if(IsDialogMessage(hParent,&msg))
00113                         return true;
00114         }
00115         else if(IsDialogMessage(msg.hwnd,&msg))
00116                 return true;
00117         return false;
00118 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines