00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #if !defined(SJMDLG_H_INCLUDED)
00012 #define SJMDLG_H_INCLUDED
00013
00014 #include "dlgwnd.h"
00015
00016 namespace sjgui{
00017
00018 namespace SJGUI_USE_STYLE
00019 {
00020 extern GLfloat def_dlg_caption_color[4];
00021 extern GLfloat def_dlg_button_text_color[4];
00022 extern CWnd::CSize def_dlg_min_size;
00023 extern int def_dlg_btn_dist;
00024 extern int def_dlg_btn_offset;
00025 extern int def_dlg_btn_panel_height;
00026 }
00071 template<class Tbutton,class Tcaption,class TclientPanel, class TbuttonPanel, class Tbase>
00072 class CDlgCtrlTmpl : public Tbase
00073 {
00074 bool m_yAutoHide;
00075 protected:
00076 Tcaption m_Caption;
00077 Tbutton m_btnOk;
00078 Tbutton m_btnCancel;
00079 TbuttonPanel m_pnlButtons;
00080 TclientPanel m_pnlClientArea;
00081
00088 virtual void Complete();
00094 public:
00095 virtual void Reshape();
00096
00097 virtual void OnComplete(){}
00099 virtual void KeyDown(int &iKey);
00104 virtual void KeyUp(int &iKey);
00106 void SetAutoHide(bool b=true){m_yAutoHide=b;}
00108 bool IsAutoHide(){return m_yAutoHide;}
00109 CDlgCtrlTmpl();
00111 void SetCaption(const char* str){m_Caption.SetText(str);}
00113 void SetCaptionColor(GLfloat R, GLfloat G, GLfloat B,GLfloat A=1.0f){m_Caption.SetColor(R,G,B,A);}
00115 void SetCaptionColor(GLfloat* col){m_Caption.SetColor(col[0],col[1],col[2],col[3]);}
00117 const char* GetCaption(){return m_Caption.GetText();}
00119 virtual void Reset(){Enable();Tbase::Reset();}
00121 bool IsOk(){return m_btnOk.IsPushed();}
00123 bool IsCancel(){return m_btnCancel.IsPushed();}
00125 virtual void OnShow(){Tbase::OnShow();SetMeMoused();ReleaseFocus(); SetMeFocused();}
00127 void RegisterButton(CWnd* pWnd){m_pnlButtons.RegisterChild(pWnd);}
00129 void UnRegisterButton(CWnd* pWnd){m_pnlButtons.UnRegisterChild(pWnd);}
00131 void RegisterToClientArea(CWnd* pWnd){m_pnlClientArea.RegisterChild(pWnd);}
00133 virtual void UnRegisterToClientArea(CWnd* pWnd){m_pnlClientArea.UnRegisterChild(pWnd);}
00135 int GetClientAreaWidth(){return m_pnlClientArea.GetWidth();};
00137 int GetClientAreaHeight(){return m_pnlClientArea.GetHeight();};
00139 TclientPanel& GetClientArea(){return m_pnlClientArea;}
00141 TbuttonPanel& GetButtonArea(){return m_pnlButtons;}
00142 };
00143
00144 template<class Tbutton,class Tcaption,class TclientPanel, class TbuttonPanel, class Tbase>
00145 inline void CDlgCtrlTmpl<Tbutton,Tcaption,TclientPanel,TbuttonPanel,Tbase>::KeyUp(int &iKey)
00146 {
00147 Tbase::KeyUp(iKey);
00148 if(m_btnOk.IsPushed() || m_btnCancel.IsPushed())Complete();
00149 switch(iKey)
00150 {
00151 case SJ_KEY_ESC:
00152 m_btnCancel.PushIt();
00153 Complete();
00154 iKey=SJ_KEY_IGNORE;
00155 break;
00156 }
00157 }
00158
00159 template<class Tbutton,class Tcaption,class TclientPanel, class TbuttonPanel, class Tbase>
00160 inline void CDlgCtrlTmpl<Tbutton,Tcaption,TclientPanel,TbuttonPanel,Tbase>::KeyDown(int &iKey)
00161 {
00162 Tbase::KeyDown(iKey);
00163 switch(iKey)
00164 {
00165
00166 case SJ_KEY_TAB:
00167 CWnd* pWnd=GetNextForFocus();
00168 if(pWnd==NULL)break;
00169 pWnd->MouseMove(pWnd->GetX(),pWnd->GetY());
00170 iKey=SJ_KEY_IGNORE;
00171 break;
00172 }
00173 }
00174
00175 template<class Tbutton,class Tcaption,class TclientPanel, class TbuttonPanel, class Tbase>
00176 inline void CDlgCtrlTmpl<Tbutton,Tcaption,TclientPanel,TbuttonPanel,Tbase>::Complete()
00177 {
00178
00179
00180 if(!m_yAutoHide)
00181 {
00182 OnComplete();
00183 return;
00184 }
00185 Disable();
00186 OnComplete();
00187
00188 Hide();
00189 }
00190
00191 template<class Tbutton,class Tcaption,class TclientPanel, class TbuttonPanel, class Tbase>
00192 inline CDlgCtrlTmpl<Tbutton,Tcaption,TclientPanel,TbuttonPanel,Tbase>::CDlgCtrlTmpl():Tbase()
00193 {
00194 SetAllowedForFocus(true);
00195 SetCaption("Dialog");
00196 SetCaptionColor(SJGUI_USE_STYLE::def_dlg_caption_color);
00197 m_btnOk.SetLabel("OK");
00198 m_btnCancel.SetLabel("Cancel");
00199 m_btnOk.SetTextColor(SJGUI_USE_STYLE::def_dlg_button_text_color);
00200 m_btnCancel.SetTextColor(m_btnOk.GetTextColor());
00201 SetMinSize(SJGUI_USE_STYLE::def_dlg_min_size);
00202 RegisterChild(&m_Caption);
00203 RegisterChild(&m_pnlButtons);
00204 RegisterChild(&m_pnlClientArea);
00205
00206
00207 m_pnlButtons.RegisterChild(&m_btnCancel);
00208 m_pnlButtons.RegisterChild(&m_btnOk);
00209 m_pnlButtons.ReverseOrder();
00210 m_pnlButtons.SetAlign(ALIGN_RIGHT,ALIGN_CENTER);
00211 m_pnlButtons.SetDist(SJGUI_USE_STYLE::def_dlg_btn_dist);
00212 m_pnlButtons.SetOffset(SJGUI_USE_STYLE::def_dlg_btn_offset);
00213 m_yAutoHide=false;
00214 m_pnlButtons.SetHeight(SJGUI_USE_STYLE::def_dlg_btn_panel_height);
00215 }
00216
00217 template<class Tbutton,class Tcaption,class TclientPanel, class TbuttonPanel, class Tbase>
00218 inline void CDlgCtrlTmpl<Tbutton,Tcaption,TclientPanel,TbuttonPanel,Tbase>::Reshape()
00219 {
00220
00221 m_Caption.PosWnd(GetBorderSize(),GetBorderSize(),GetWidth()-GetBorderSize()*2,m_Caption.GetHeight());
00222
00223 m_pnlButtons.PosWnd(GetBorderSize(),GetHeight()-m_pnlButtons.GetHeight()-GetBorderSize()*2,
00224 GetWidth()-GetBorderSize()*2,m_pnlButtons.GetHeight());
00225
00226 m_pnlClientArea.PosWnd( GetBorderSize(),m_Caption.GetBottom(),
00227 GetWidth()-GetBorderSize()*2,m_pnlButtons.GetY()-m_Caption.GetBottom());
00228 m_ClAr=m_pnlClientArea.GetPos();
00229 Tbase::Reshape();
00230 }
00231
00232 }
00233
00234 #endif // !defined(SJMDLG_H_INCLUDED)