listener.h

Go to the documentation of this file.
00001 /*      Listener.h - the Listener class - MAXScript listener windows
00002  *
00003  *      Copyright (c) John Wainwright, 1996
00004  *      
00005  */
00006 
00007 #pragma once
00008 
00009 #include <windowsx.h>
00010 #include "..\foundation\pipe.h"
00011 #include "..\compiler\thunks.h"
00012 
00013 // helper methods for editor windows
00014 ScripterExport int get_cur_line(HWND window, MSTR& line, bool stripEOL);
00015 ScripterExport void set_edit_box_font(HWND window, const MCHAR* font_name);
00016 ScripterExport void set_edit_box_font_size(HWND window, int fontSize);
00017 
00018 extern GlobalThunk* listener_result_thunk;
00019 
00020 extern ScripterExport BOOL end_keyboard_input;
00021 extern ScripterExport BOOL start_keyboard_input;
00022 extern ScripterExport MCHAR* keyboard_input;
00023 extern ScripterExport Value* keyboard_terminator;
00024 extern ScripterExport Array* keyboard_input_terminators;
00025 
00026 // the Scintilla styles for the edit box
00027 #define LISTENER_STYLE_INPUT    0
00028 #define LISTENER_STYLE_OUTPUT   1
00029 #define LISTENER_STYLE_MESSAGE  2
00030 #define LISTENER_STYLE_LABEL    3
00031 
00032 extern COLORREF input_text_color;
00033 extern COLORREF output_text_color;
00034 extern COLORREF message_text_color;
00035 extern COLORREF label_text_color;
00036 
00037 // listener flag values
00038 #define LSNR_INPUT_MODE_MASK    0x000F
00039 #define LSNR_KEYINPUT_OFF       0x0000
00040 #define LSNR_KEYINPUT_LINE      0x0001
00041 #define LSNR_KEYINPUT_CHAR      0x0002
00042 #define LSNR_SHOWING            0x0010  // MAXScript is forcing a show, ignore all other ShowWindows
00043 #define LSNR_NO_MACRO_REDRAW    0x0020  // disable drawing in macro-rec box (to get round bug in WM_SETREDRAW)
00044 #define LSNR_QUITMAX_RUN        0x0040  // quitMax run - WM_CLOSE posted to main thread
00045 
00046 // listener flag values added for r10 to support scintilla control
00047 #define LSNR_STYLE_MASK         0x0300  // listener style flag mask
00048 #define LSNR_STYLE_INPUT        0x0000  // LISTENER_STYLE_INPUT set
00049 #define LSNR_STYLE_OUTPUT       0x0100  // LISTENER_STYLE_OUTPUT set
00050 #define LSNR_STYLE_MESSAGE      0x0200  // LISTENER_STYLE_MESSAGE set
00051 #define LSNR_BLOCK_MINI_UPDATES 0x0400  // mini updates blocked
00052 
00053 #define EDIT_BOX_ITEM           1001    // listener edit box dlg item #
00054 #define MACROREC_BOX_ITEM       1002    // listener macro-recorder edit box dlg item #
00055 
00056 // Forward declaration
00057 class ListenerViewWindow;
00058 
00059 class Listener : public Value
00060 {
00061 private:
00063     static HANDLE mShutdown_Event;
00066     static bool mBailout;
00067     HANDLE      listener_thread;
00068     DWORD       thread_id;
00069     
00070 public:
00071     HWND        listener_window;        // main listener window
00072     HWND        edit_box;               // edit control for main type-in
00073     HWND        macrorec_box;           // edit control for macro-recorder output
00074     HWND        mini_listener;          // mini-listener parent window in the MAX status panel
00075     HWND        mini_edit;              // mini-listener edit control for type_in
00076     HWND        mini_macrorec;          // mini-listener edit control for macro-recorder output
00077     WindowStream* edit_stream;          // stream for the main edit box
00078     WindowStream* macrorec_stream;      // stream for the macro-recorder edit box
00079     WindowStream* mini_edit_stream;     // stream for the mini edit box
00080     WindowStream* mini_macrorec_stream; // stream for the mini macro-recorder edit box
00081     Pipe*       source_pipe;            // the source pipe for the listener, source written to, compiler reads from
00082     int         flags;
00083     ListenerViewWindow* lvw;            // the ViewWindow instance for the listener
00084 
00086 
00087     Listener(HINSTANCE mxs_instance, HWND MAX_window);
00089 
00091     ~Listener();
00092 
00094     static DWORD run(Listener *l);
00095     
00097 
00099     void        stop();
00100     
00101     void        create_listener_window(HINSTANCE hInstance, HWND hwnd);
00102 
00103     void        gc_trace();
00104     void        collect() { delete this; }
00105 
00106     ScripterExport void set_keyinput_mode(int mode) { flags = (flags & ~LSNR_INPUT_MODE_MASK) | mode; }
00107     // get/set the current Scintilla style for the edit box
00108     ScripterExport int set_style(int style);
00109     ScripterExport int get_style();
00110     ScripterExport void set_font(const MCHAR* font_name);
00111     ScripterExport void set_font_size(int fontSize);
00112     // get/set whether changes to listener windows update mini windows
00113     ScripterExport bool set_block_mini_updates(bool blocked);
00114     ScripterExport bool get_block_mini_updates();
00115 };
00116 
00117 // ViewWindow subclass for putting the listener in a MAX viewport
00118 class ListenerViewWindow : public ViewWindow
00119 {
00120 public:
00121     MCHAR *GetName();
00122     HWND CreateViewWindow(HWND hParent, int x, int y, int w, int h);
00123     void DestroyViewWindow(HWND hWnd);
00124     BOOL CanCreate();
00125 };
00126 
00127 class ListenerMessageData 
00128 {
00129 public:
00130     WPARAM wParam;
00131     LPARAM lParam;
00132     HANDLE message_event;
00133     ListenerMessageData(WPARAM wp, LPARAM lp, HANDLE me) { wParam = wp; lParam = lp; message_event = me; }
00134 };
00135 
00136 #define CLICK_STACK_SIZE    8           // number of clicked-at locations to remember for ctrl-R return
00137 struct edit_window
00138 {
00139     edit_window*    next;
00140     edit_window*    prev;
00141     Value*          file_name;
00142 
00143     bool            dont_flag_save; // deprecated
00144     bool            needs_save;     // deprecated
00145 
00146     HWND            window;
00147     HWND            edit_box;
00148     int             sr_offset;
00149     int             click_tos;
00150     int             click_at[CLICK_STACK_SIZE];
00151     bool            editing;
00152     IUnknown*       pDoc;
00153 
00154     INT_PTR         new_rollout();  
00155     INT_PTR         edit_rollout(); 
00156     INT_PTR         new_rollout(bool delete_ew);    
00157     INT_PTR         edit_rollout(bool delete_ew);   
00158     static void     gc_trace();
00159     bool            GetNeedsSave();
00160     void            ClearNeedsSave();
00161 };
00162