src/widgets.cpp

Go to the documentation of this file.
00001 /*
00002 * Copyright (c) 2006 by Kirill Kolodyazhniy.
00003 * See the file "license.terms" for information on usage and redistribution
00004 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
00005 */
00006 
00007 #include "stdinc.h"
00008 #ifdef _MSC_VER
00009 #include <dbghelp.h>
00010 #endif
00011 #include <tchar.h>
00012 #include <assert.h>
00013 #include "icon.h"
00014 #include "eventhandler.h"
00015 #include "menu.h"
00016 #include "widget.h"
00017 #include "widgets.h"
00018 #include "exception.h"
00019 namespace MWidgets
00020 {
00021 
00022         /*******************************************************************************/
00023         Widgets* Widgets::m_pSelf=NULL;
00024         /*******************************************************************************/
00025         void Widgets::Init(Icon* pBigIcon,Icon* pSmallIcon)
00026         {
00027                 if(m_pSelf==NULL)
00028                         m_pSelf=new Widgets();
00029                 else
00030                         EXCEPT("Widgets allready initialized!");
00031 
00032                 InitCommonControls();
00033 
00034                 WNDCLASSEX wc;
00035                 wc.cbSize = sizeof(WNDCLASSEX);
00036 
00037                 HINSTANCE m_hInstance=GetModuleHandle(NULL);
00038 
00039                 if(GetClassInfoEx(m_hInstance,"MicroWidget",&wc)==FALSE)
00040                 {
00041                         wc.style =0;
00042                         wc.lpfnWndProc = Widget::WindowProcedure;
00043                         wc.cbClsExtra = 0;
00044                         wc.cbWndExtra = 0;
00045                         wc.hInstance = m_hInstance;
00046                         if(pBigIcon)
00047                                 wc.hIcon = pBigIcon->GetHICON();
00048                         else
00049                                 wc.hIcon = NULL;
00050                         wc.hCursor = LoadCursor(NULL,IDC_ARROW);
00051                         wc.hbrBackground = CreateSolidBrush(GetSysColor (COLOR_MENU));
00052                         wc.lpszMenuName = NULL;
00053                         wc.lpszClassName = "MicroWidget";
00054                         if(pSmallIcon)
00055                                 wc.hIconSm = pSmallIcon->GetHICON();
00056                         else
00057                                 wc.hIconSm = NULL;
00058 
00059                         //Register main window class
00060                         m_pSelf->m_aWidget=RegisterClassEx(&wc);
00061                         if(!m_pSelf->m_aWidget)
00062                         {
00063                                 EXCEPT("RegisterClassEx");
00064                         };
00065                 }
00066         };
00067         /*******************************************************************************/
00068         Widgets* Widgets::Instance()
00069         {
00070                 try
00071                 {
00072                         if(m_pSelf==NULL)
00073                                 EXCEPT("Windgets are not initialized!");
00074                         return m_pSelf;
00075                 }
00076                 catch(Exception e)
00077                 {
00078                         CATCHEXCEPT(e,"Widgets::Instance");
00079                 };
00080         };
00081         /*******************************************************************************/
00082         Widgets::Widgets()
00083         {
00084                 m_aWidget=0;
00085                 count=0;
00086                 uniqueId=0;
00087                 running=false;
00088         };
00089         /*******************************************************************************/
00090         Widgets::~Widgets()
00091         {
00092         }
00093         /*******************************************************************************/
00094         void Widgets::AddWidget()
00095         {
00096                 count++;
00097         };
00098         /*******************************************************************************/
00099         void Widgets::DelWidget()
00100         {
00101                 count--;
00102         };
00103         /*******************************************************************************/
00104         void Widgets::Run()
00105         {
00106                 if(!running)
00107                 {
00108                         running=true;
00109                         MSG msg;
00110                         // Main message loop:
00111                         while(count>0)
00112                         {
00113                                 if(PeekMessage( &msg, NULL, 0, 0,PM_REMOVE))
00114                                 {
00115                                         TranslateMessage(&msg);
00116                                         DispatchMessage(&msg);
00117                                 }
00118                         }
00119                         running=false;
00120                 }
00121         };
00122         /*******************************************************************************/
00123         unsigned int Widgets::GetNewId()
00124         {
00125                 uniqueId++;
00126                 return uniqueId;
00127         };
00128         /*******************************************************************************/
00129         void Widgets::Destroy()
00130         {
00131                 try
00132                 {
00133                         if(m_pSelf)
00134                         {
00135                                 if(m_pSelf->count<=0)
00136                                         delete m_pSelf;
00137                                 else
00138                                         EXCEPT("There are some widgets!");
00139                         }
00140                 }
00141                 catch(Exception e)
00142                 {
00143                         CATCHEXCEPT(e,"Widgets::Destroy");
00144                 };
00145         };
00146         /*******************************************************************************/
00147         ATOM Widgets::GetAtom()
00148         {
00149                 return m_aWidget;
00150         };
00151         /*******************************************************************************/
00152 };

Generated on Thu Oct 26 13:47:45 2006 for MWidgets by  doxygen 1.4.7