Back to index

lightning-sunbird  0.9+nobinonly
JSConsole.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is mozilla.org code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1998
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either of the GNU General Public License Version 2 or later (the "GPL"),
00026  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 
00038 #ifndef jsconsole_h__
00039 #define jsconsole_h__
00040 
00041 #include <windows.h>
00042 #include "nsIScriptContext.h"
00043 
00044 #define OPEN_DIALOG         0
00045 #define SAVE_DIALOG         1
00046 
00047 typedef void (*DESTROY_NOTIFICATION) ();
00048 
00049 class JSConsole {
00050 
00051 private:
00052     HWND mMainWindow;
00053     HWND mEditWindow;
00054 
00055     DESTROY_NOTIFICATION mDestroyNotification;
00056 
00057     // keep info from the OPENFILENAME struct
00058     struct FileInfo {
00059         CHAR mCurrentFileName[MAX_PATH];
00060         WORD mFileOffset;
00061         WORD mFileExtension;
00062 
00063         void Init() {mCurrentFileName[0] = '\0'; mFileOffset = 0; mFileExtension = 0;}
00064     } mFileInfo;
00065 
00066     // one context per window
00067     nsIScriptContext *mContext;
00068 
00069 public:
00070     static HINSTANCE sAppInstance;
00071     static HACCEL sAccelTable;
00072     static CHAR sDefaultCaption[];
00073 
00074     static BOOL RegisterWidget();
00075     static JSConsole* CreateConsole();
00076     static LRESULT CALLBACK WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
00077 
00078 private:
00079     static BOOL mRegistered;
00080 
00081 public:
00082     JSConsole(HWND aMainWindow, HWND aEditControl);
00083     ~JSConsole();
00084 
00085     BOOL LoadFile();
00086     BOOL SaveFile();
00087 
00088     BOOL OpenFileDialog(UINT aOpenOrSave);
00089     inline BOOL CanSave() { return mFileInfo.mCurrentFileName[0] != '\0'; }
00090     void SetFileName(LPSTR aFileName);
00091 
00092     HWND GetMainWindow() { return mMainWindow; }
00093     void SetNotification(DESTROY_NOTIFICATION aNotification) { mDestroyNotification = aNotification; }
00094     void SetContext(nsIScriptContext *aContext) {
00095       NS_IF_ADDREF(aContext);
00096       NS_IF_RELEASE(mContext);
00097       mContext = aContext;
00098     }
00099 
00100     void EvaluateText(UINT aStartSel, UINT aEndSel);
00101 
00102     // windows messages
00103     LRESULT OnSize(DWORD aResizeFlags, UINT aWidth, UINT aHeight);
00104     LRESULT OnInitMenu(HMENU aMenu, UINT aPos, BOOL aIsSystem);
00105     LRESULT OnSetFocus(HWND aWnd);
00106 
00107     void OnDestroy();
00108 
00109     // menu items
00110     void OnFileNew();
00111     void OnEditUndo();
00112     void OnEditCut();
00113     void OnEditCopy();
00114     void OnEditPaste();
00115     void OnEditDelete();
00116     void OnEditSelectAll();
00117     void OnCommandEvaluateAll();
00118     void OnCommandEvaluateSelection();
00119     void OnCommandInspector();
00120     void OnHelp();
00121 
00122 private:
00123     void InitEditMenu(HMENU aMenu);
00124     void InitCommandMenu(HMENU aMenu);
00125 };
00126 
00127 #endif // jsconsole_h__
00128