Revision: 2532
http://emerge.svn.sourceforge.net/emerge/?rev=2532&view=rev
Author: ir0nh34d
Date: 2009-07-03 02:12:09 +0000 (Fri, 03 Jul 2009)
Log Message:
-----------
Remove more global pointers
Modified Paths:
--------------
trunk/Source/emergeCommand/Applet.cpp
trunk/Source/emergeCommand/Applet.h
trunk/Source/emergeCommand/Command.cpp
trunk/Source/emergeCommand/Command.h
trunk/Source/emergeCommand/Config.cpp
trunk/Source/emergeCommand/Config.h
trunk/Source/emergeCommand/CustomSource.cpp
trunk/Source/emergeCommand/CustomSource.h
trunk/Source/emergeCommand/main.cpp
Modified: trunk/Source/emergeCommand/Applet.cpp
===================================================================
--- trunk/Source/emergeCommand/Applet.cpp 2009-07-02 16:04:49 UTC (rev 2531)
+++ trunk/Source/emergeCommand/Applet.cpp 2009-07-03 02:12:09 UTC (rev 2532)
@@ -19,12 +19,7 @@
//---- --------------------------------------------------------------------------------------------------------
#include "Applet.h"
-#include "Config.h"
-extern Applet *pApplet;
-Settings *pSettings = NULL;
-Command *pCommand = NULL;
-Config *pConfig = NULL;
WCHAR myName[ ] = TEXT("emergeCommand");
WCHAR szClassName[ ] = TEXT("Shell_CommandWnd");
@@ -37,8 +32,11 @@
// Returns: None
// Purpose: Tells us our timer tick has occurred - so update text with new time
//---- --------------------------------------------------------------------------------------------------------
-VOID CALLBACK Applet::TimerProc(HWND hWnd, UINT uMsg UNUSED, UINT idEvent, DWORD dwTime UNUSED)
+LRESULT Applet::DoTimer(UINT idEvent)
{
+ if (idEvent == MOUSE_TIMER)
+ return BaseApplet::DoTimer(idEvent);
+
// Only draw the time if this is a timer event and the edit box isn't focused
if (idEvent == ID_CLOCKTIMER)
{
@@ -50,12 +48,16 @@
stVal = localtime(&tVal);
// Format the time
- pApplet->SetCommandText((WCHAR*)ELwcsftime(pSettings->GetDisplayTimeFormat(), stVal).c_str());
- pApplet->UpdateTip((WCHAR*)ELwcsftime(pSettings->GetDisplayTipFormat(), stVal).c_str());
+ SetCommandText((WCHAR*)ELwcsftime(pSettings->GetDisplayTimeFormat(), stVal).c_str());
+ UpdateTip((WCHAR*)ELwcsftime(pSettings->GetDisplayTipFormat(), stVal).c_str());
- if (IsWindowVisible(hWnd))
- pApplet->DrawAlphaBlend();
+ if (IsWindowVisible(mainWnd))
+ DrawAlphaBlend();
+
+ return 0;
}
+
+ return 1;
}
//---- --------------------------------------------------------------------------------------------------------
@@ -70,8 +72,17 @@
LRESULT CALLBACK Applet::WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
COPYDATASTRUCT *cpData;
+ CREATESTRUCT *cs;
+ static Applet *pApplet = NULL;
- if ((pApplet == NULL) || (pSettings == NULL) || (pCommand == NULL))
+ if (message == WM_CREATE)
+ {
+ cs = (CREATESTRUCT*)lParam;
+ pApplet = (Applet*)cs->lpCreateParams;
+ return DefWindowProc(hwnd, message, wParam, lParam);
+ }
+
+ if (pApplet == NULL)
return DefWindowProc(hwnd, message, wParam, lParam);
switch (message)
@@ -191,11 +202,11 @@
return ret;
// Initialize and Scheme classes
- pConfig = new Config(mainInst, mainWnd);
pSettings = (Settings*)pBaseSettings;
+ pConfig = new Config(mainInst, mainWnd, pSettings);
// Create the Command Window
- pCommand = new Command(mainWnd, mainInst);
+ pCommand = new Command(mainWnd, mainInst, pSettings);
if (!pCommand->Init())
{
delete pCommand;
@@ -206,7 +217,7 @@
// Set the window transparency
UpdateGUI();
- SetTimer(mainWnd, ID_CLOCKTIMER, 1000, (TIMERPROC)TimerProc);
+ SetTimer(mainWnd, ID_CLOCKTIMER, 1000, NULL);
return 1;
}
@@ -291,7 +302,8 @@
if (pCommand)
{
ShowWindow(mainWnd, SW_HIDE);
- pCommand->UpdateGUI();
+ pCommand->UpdateGUI(guiInfo);
+ pCommand->SetHidden(appletHidden);
ShowWindow(pCommand->GetCommandWnd(), SW_SHOW);
return 0;
}
@@ -312,6 +324,6 @@
GUIINFO Applet::GetGUIInfo()
{
- return pApplet->guiInfo;
+ return guiInfo;
}
Modified: trunk/Source/emergeCommand/Applet.h
===================================================================
--- trunk/Source/emergeCommand/Applet.h 2009-07-02 16:04:49 UTC (rev 2531)
+++ trunk/Source/emergeCommand/Applet.h 2009-07-03 02:12:09 UTC (rev 2532)
@@ -42,19 +42,20 @@
#include <locale.h>
#include <vector>
-#include "Command.h"
#include "../emergeAppletEngine/emergeAppletEngine.h"
#include "../emergeBaseClasses/BaseApplet.h"
+#include "Config.h"
+#include "Command.h"
class Applet: public BaseApplet
{
private:
+ Settings *pSettings;
+ Config *pConfig;
+ Command *pCommand;
WCHAR commandText[MAX_LINE_LENGTH];
HFONT mainFont;
static LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);
- static LRESULT CALLBACK HookCallWndProc(int nCode, WPARAM wParam, LPARAM lParam);
- static VOID CALLBACK TimerProc(HWND hWnd, UINT uMsg, UINT idEvent, DWORD dwTime);
- static BOOL CALLBACK EnumFullScreenWindows(HWND hwnd, LPARAM lParam);
protected:
virtual BaseSettings *createSettings();
@@ -66,6 +67,7 @@
GUIINFO GetGUIInfo();
UINT Initialize();
LRESULT DoMove();
+ LRESULT DoTimer(UINT idEvent);
void AppletUpdate();
void WriteAppletSettings();
LRESULT DoButtonDown(UINT message, WPARAM wParam, LPARAM lParam);
Modified: trunk/Source/emergeCommand/Command.cpp
===================================================================
--- trunk/Source/emergeCommand/Command.cpp 2009-07-02 16:04:49 UTC (rev 2531)
+++ trunk/Source/emergeCommand/Command.cpp 2009-07-03 02:12:09 UTC (rev 2532)
@@ -24,31 +24,22 @@
//---- --------------------------------------------------------------------------------------------------------
#include "Command.h"
-#include "CustomSource.h"
#include "Applet.h"
WCHAR szCommandClass[] = TEXT("CommandWnd");
-extern Command *pCommand;
-extern Settings *pSettings;
-extern Applet *pApplet;
-IAutoComplete *pac;
-IAutoComplete2 *pac2;
-IObjMgr *pom;
-IUnknown *fileSource;
-IEnumString *historySource;
-CustomSource *history;
-
-Command::Command(HWND mainWnd, HINSTANCE hInstance)
+Command::Command(HWND mainWnd, HINSTANCE hInstance, Settings *pSettings)
{
pac = NULL;
pom = NULL;
fileSource = NULL;
historySource = NULL;
hText = NULL;
+ appletHidden = false;
mainInst = hInstance;
- (*this).mainWnd = mainWnd;
+ this->mainWnd = mainWnd;
+ this->pSettings = pSettings;
registered = true;
}
@@ -96,7 +87,7 @@
NULL,
NULL,
mainInst,
- NULL);
+ this);
// If the window failed to get created, unregister the class and quit the program
if (!commandWnd)
@@ -119,7 +110,14 @@
WCHAR error[MAX_LINE_LENGTH];
int length;
WCHAR buf[MAX_LINE_LENGTH];
+ static Command *pCommand = NULL;
+ if (message == WM_APP+1)
+ pCommand = (Command*)lParam;
+
+ if (pCommand == NULL)
+ return DefWindowProc(hwnd, message, wParam, lParam);
+
if (message == WM_KEYDOWN)
{
// When the user presses return - execute the command
@@ -132,7 +130,7 @@
{
buf[length] = '\0';
if (ELExecuteAll(buf, (WCHAR*)TEXT("\0")))
- history->AddElement(buf);
+ pCommand->AddElement(buf);
else
ELMessageBox(GetDesktopWindow(), error, (WCHAR*)TEXT("emergeCommand"), ELMB_ICONWARNING|ELMB_OK);
}
@@ -152,6 +150,11 @@
return CallWindowProc(pCommand->GetWndProc(),hwnd,message,wParam,lParam);
}
+void Command::AddElement(WCHAR *element)
+{
+ history->AddElement(element);
+}
+
//---- --------------------------------------------------------------------------------------------------------
// Function: CommandProc
// Required: HWND hwnd - window handle that message was sent to
@@ -163,6 +166,19 @@
//---- --------------------------------------------------------------------------------------------------------
LRESULT CALLBACK Command::CommandProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
+ CREATESTRUCT *cs;
+ static Command *pCommand = NULL;
+
+ if (message == WM_CREATE)
+ {
+ cs = (CREATESTRUCT*)lParam;
+ pCommand = (Command*)cs->lpCreateParams;
+ return DefWindowProc(hwnd, message, wParam, lParam);
+ }
+
+ if (pCommand == NULL)
+ return DefWindowProc(hwnd, message, wParam, lParam);
+
switch (message)
{
// Needed to handle changing the system colors. It forces
@@ -174,14 +190,14 @@
// Repaint the icons as the window size is changing
case WM_WINDOWPOSCHANGING:
{
- if (!_wcsicmp(pApplet->pBaseSettings->GetZPosition(), TEXT("bottom")))
+ if (!_wcsicmp(pCommand->GetZPosition(), TEXT("bottom")))
((WINDOWPOS *)lParam)->flags |= SWP_NOZORDER;
}
break;
// Don't close on alt-F4
case WM_SYSCOMMAND:
- return pApplet->DoSysCommand(hwnd, message, wParam, lParam);
+ return pCommand->DoSysCommand(hwnd, message, wParam, lParam);
// Send a quit message when the window is destroyed
case WM_DESTROY:
@@ -205,7 +221,7 @@
if (GetForegroundWindow() != hwnd)
{
ShowWindow(hwnd, SW_HIDE);
- pApplet->Show();
+ pCommand->Show();
}
return 0;
@@ -216,10 +232,40 @@
return 0;
}
-void Command::UpdateEdit(int width, int height)
+void Command::SetHidden(bool appletHidden)
{
+ this->appletHidden = appletHidden;
+}
+
+WCHAR *Command::GetZPosition()
+{
+ return pSettings->GetZPosition();
+}
+
+LRESULT Command::DoSysCommand(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
+{
+ switch (wParam)
+ {
+ case SC_CLOSE:
+ case SC_MAXIMIZE:
+ case SC_MINIMIZE:
+ break;
+ default:
+ return DefWindowProc(hwnd, message, wParam, lParam);
+ }
+ return 0;
+}
+
+void Command::Show()
+{
+ if (!appletHidden)
+ ShowWindow(mainWnd, SW_SHOWNOACTIVATE);
+}
+
+void Command::UpdateEdit(GUIINFO guiInfo, int width, int height)
+{
int top, bottom;
- int dragBorder = pApplet->GetGUIInfo().dragBorder + pApplet->GetGUIInfo().bevelWidth + pApplet->GetGUIInfo().padding;
+ int dragBorder = guiInfo.dragBorder + guiInfo.bevelWidth + guiInfo.padding;
LPVOID lpVoid;
if (_wcsicmp(pSettings->GetCommandVerticalAlign(), TEXT("center")) == 0)
@@ -294,7 +340,7 @@
if (!historySource)
{
- history = new CustomSource();
+ history = new CustomSource(pSettings);
history->QueryInterface(IID_IEnumString, &lpVoid);
historySource = reinterpret_cast <IEnumString*> (lpVoid);
@@ -351,9 +397,10 @@
commandWnd,
NULL,
mainInst,
- NULL);
+ this);
wpOld = (WNDPROC)SetWindowLongPtr(hText,GWLP_WNDPROC,(LONG_PTR)EditProc);
+ SendMessage(hText, WM_APP+1, 0, (LPARAM)this);
if (textFont)
DeleteObject((HFONT)textFont);
@@ -399,17 +446,17 @@
}
}
-void Command::UpdateGUI()
+void Command::UpdateGUI(GUIINFO guiInfo)
{
- int dragBorder = pApplet->GetGUIInfo().dragBorder + pApplet->GetGUIInfo().bevelWidth + pApplet->GetGUIInfo().padding;
+ int dragBorder = guiInfo.dragBorder + guiInfo.bevelWidth + guiInfo.padding;
- EAEUpdateGUI(commandWnd, pApplet->GetGUIInfo().windowShadow, pApplet->pBaseSettings->GetZPosition());
+ EAEUpdateGUI(commandWnd, guiInfo.windowShadow, pSettings->GetZPosition());
- SetWindowPos(commandWnd, NULL, pApplet->pBaseSettings->GetX(), pApplet->pBaseSettings->GetY(),
- pApplet->pBaseSettings->GetWidth() + (2 * dragBorder), pApplet->pBaseSettings->GetHeight() + (2 * dragBorder),
+ SetWindowPos(commandWnd, NULL, pSettings->GetX(), pSettings->GetY(),
+ pSettings->GetWidth() + (2 * dragBorder), pSettings->GetHeight() + (2 * dragBorder),
SWP_NOZORDER);
- UpdateEdit(pApplet->pBaseSettings->GetWidth() + (2 * dragBorder), pApplet->pBaseSettings->GetHeight() + (2 * dragBorder));
+ UpdateEdit(guiInfo, pSettings->GetWidth() + (2 * dragBorder), pSettings->GetHeight() + (2 * dragBorder));
- SetLayeredWindowAttributes(commandWnd, 0, pApplet->GetGUIInfo().alphaActive, LWA_ALPHA);
+ SetLayeredWindowAttributes(commandWnd, 0, guiInfo.alphaActive, LWA_ALPHA);
}
Modified: trunk/Source/emergeCommand/Command.h
===================================================================
--- trunk/Source/emergeCommand/Command.h 2009-07-02 16:04:49 UTC (rev 2531)
+++ trunk/Source/emergeCommand/Command.h 2009-07-03 02:12:09 UTC (rev 2532)
@@ -32,6 +32,7 @@
#define MOUSE_POLL_TIME 250
#include "Settings.h"
+#include "CustomSource.h"
#include "../emergeGraphics/emergeGraphics.h"
#include <windows.h>
#include <time.h>
@@ -52,19 +53,32 @@
#endif
class Command
- {
- public:
- Command(HWND mainWnd, HINSTANCE hInstance);
+{
+public:
+ Command(HWND mainWnd, HINSTANCE hInstance, Settings *pSettings);
~Command();
bool Init();
- void UpdateGUI();
+ void UpdateGUI(GUIINFO guiInfo);
HWND GetCommandWnd();
HWND GetMainWnd();
WNDPROC GetWndProc();
- void UpdateEdit(int width, int height);
+ void UpdateEdit(GUIINFO, int width, int height);
void ShowTextWindow();
+ WCHAR *GetZPosition();
+ LRESULT DoSysCommand(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
+ void Show();
+ void AddElement(WCHAR *element);
+ void SetHidden(bool appletHidden);
- private:
+private:
+ bool appletHidden;
+ Settings *pSettings;
+ IAutoComplete *pac;
+ IAutoComplete2 *pac2;
+ IObjMgr *pom;
+ IUnknown *fileSource;
+ IEnumString *historySource;
+ CustomSource *history;
WCHAR fontName[MAX_RUN_STRING];
int dragBorder;
UINT zOrder;
@@ -77,7 +91,7 @@
DWORD height;
static LRESULT CALLBACK CommandProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
static LRESULT CALLBACK EditProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
- };
+};
#endif
Modified: trunk/Source/emergeCommand/Config.cpp
===================================================================
--- trunk/Source/emergeCommand/Config.cpp 2009-07-02 16:04:49 UTC (rev 2531)
+++ trunk/Source/emergeCommand/Config.cpp 2009-07-03 02:12:09 UTC (rev 2532)
@@ -20,14 +20,16 @@
#include "Config.h"
-extern Config *pConfig;
-extern Settings *pSettings;
-
BOOL CALLBACK Config::ConfigDlgProc(HWND hwndDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
+ static Config *pConfig = NULL;
+
switch (message)
{
case WM_INITDIALOG:
+ pConfig = reinterpret_cast<Config*>(lParam);
+ if (!pConfig)
+ break;
return pConfig->DoInitDialog(hwndDlg);
case WM_COMMAND:
@@ -37,10 +39,11 @@
return FALSE;
}
-Config::Config(HINSTANCE hInstance, HWND mainWnd)
+Config::Config(HINSTANCE hInstance, HWND mainWnd, Settings *pSettings)
{
- (*this).hInstance = hInstance;
- (*this).mainWnd = mainWnd;
+ this->pSettings = pSettings;
+ this->hInstance = hInstance;
+ this->mainWnd = mainWnd;
}
Config::~Config()
@@ -51,7 +54,7 @@
int Config::Show()
{
- return (int)DialogBox(hInstance, MAKEINTRESOURCE(IDD_CONFIG), mainWnd, (DLGPROC)ConfigDlgProc);
+ return (int)DialogBoxParam(hInstance, MAKEINTRESOURCE(IDD_CONFIG), mainWnd, (DLGPROC)ConfigDlgProc, (LPARAM)this);
}
BOOL Config::DoInitDialog(HWND hwndDlg)
Modified: trunk/Source/emergeCommand/Config.h
===================================================================
--- trunk/Source/emergeCommand/Config.h 2009-07-02 16:04:49 UTC (rev 2531)
+++ trunk/Source/emergeCommand/Config.h 2009-07-03 02:12:09 UTC (rev 2532)
@@ -23,12 +23,11 @@
#include "Settings.h"
#include "resource.h"
-#include "Applet.h"
class Config
{
public:
- Config(HINSTANCE hInstance, HWND mainWnd);
+ Config(HINSTANCE hInstance, HWND mainWnd, Settings *pSettings);
~Config();
int Show();
BOOL DoInitDialog(HWND hwndDlg);
@@ -37,6 +36,7 @@
bool DoFontChooser(HWND hwndDlg);
private:
+ Settings *pSettings;
LOGFONT newFont;
HINSTANCE hInstance;
HWND mainWnd;
Modified: trunk/Source/emergeCommand/CustomSource.cpp
===================================================================
--- trunk/Source/emergeCommand/CustomSource.cpp 2009-07-02 16:04:49 UTC (rev 2531)
+++ trunk/Source/emergeCommand/CustomSource.cpp 2009-07-03 02:12:09 UTC (rev 2532)
@@ -19,16 +19,14 @@
//---
#include "../emergeLib/emergeLib.h"
-#include "Settings.h"
#include "CustomSource.h"
-extern Settings *pSettings;
-
-CustomSource::CustomSource()
+CustomSource::CustomSource(Settings *pSettings)
{
currentElement = 0;
refCount = 0;
pSettings->BuildHistoryList();
+ this->pSettings = pSettings;
}
CustomSource::~CustomSource()
@@ -54,7 +52,7 @@
{
*target = NULL;
- CustomSource *copy = new CustomSource();
+ CustomSource *copy = new CustomSource(pSettings);
*target = copy;
Modified: trunk/Source/emergeCommand/CustomSource.h
===================================================================
--- trunk/Source/emergeCommand/CustomSource.h 2009-07-02 16:04:49 UTC (rev 2531)
+++ trunk/Source/emergeCommand/CustomSource.h 2009-07-03 02:12:09 UTC (rev 2532)
@@ -27,17 +27,19 @@
#define __CUSTOMSOURCE_H
#include <stdio.h>
+#include "Settings.h"
//#define MAX_HISTORY 9
class CustomSource : public IEnumString
{
private:
+ Settings *pSettings;
ULONG refCount;
ULONG currentElement;
public:
- CustomSource();
+ CustomSource(Settings *pSettings);
virtual ~CustomSource();
HRESULT STDMETHODCALLTYPE QueryInterface(REFIID, void**);
STDMETHODIMP_(ULONG) AddRef();
Modified: trunk/Source/emergeCommand/main.cpp
===================================================================
--- trunk/Source/emergeCommand/main.cpp 2009-07-02 16:04:49 UTC (rev 2531)
+++ trunk/Source/emergeCommand/main.cpp 2009-07-03 02:12:09 UTC (rev 2532)
@@ -20,9 +20,6 @@
#include "Applet.h"
-Applet *pApplet = NULL;
-HWND commandWnd = NULL;
-
BOOL CALLBACK FocusWindowEnum(HWND hwnd, LPARAM lParam UNUSED)
{
WCHAR window[MAX_PATH];
@@ -61,6 +58,7 @@
int nCmdShow UNUSED)
{
+ Applet *pApplet;
MSG messages;
// Check to see if iTray is already running, if so exit
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|