Author Topic: When does the _MDIChildGetWindow method become "fully active"?  (Read 6155 times)

TxDot

  • Community Member
  • Posts: 38
  • Hero Points: 0
When does the _MDIChildGetWindow method become "fully active"?
« on: October 18, 2013, 02:03:11 PM »
I'm updating my "resize" macro to use the _MDIChildGetWindow method to set the size of the windows (buffers). This works if I enter the command manually, or if I double click a file that is opened in SE. But when I open a project (via the Project menu) I get the following error;
Code: [Select]
This property or method is not allowed on this object
resize.ex 774 resize_window()   p_window_id: 5   p_object: OI_FORM   p_name:
resize.ex 1071 _buffer_add_resize(31,D:\xxxxxxx\Data\SlickEdit\macros\resize.e,0)   p_window_id: 202   p_object: OI_EDITOR   p_name:
files.ex 10172 call_list(_buffer_add_,31,D:\xxxxxxx\Data\SlickEdit\macros\resize.e,0)   p_window_id: 202   p_object: OI_EDITOR   p_name:
files.ex 4161 files:edit_status(0,0,31 5,32,)   p_window_id: 202   p_object: OI_EDITOR   p_name:
files.ex 3221 files:edit2(-w   +ftext  "D:\xxxxxxx\Data\SlickEdit\macros\resize.e",32,0)   p_window_id: 202   p_object: OI_EDITOR   p_name:
files.ex 392 edit(-w   +ftext  "D:\xxxxxxx\Data\SlickEdit\macros\resize.e",32,0)   p_window_id: 202   p_object: OI_EDITOR   p_name:
restore.ex 4023 restore:process_buffer(BN="\xxxxxxx\Data\SlickEdit\macros\resize.e",,
   3:   MA=1 74 1  TABS=1 4  WWS=1 IWT=0 ST=0 IN=2 BW=0 US=32000 RO=0 SE=0 SN=0 BIN=0 MN=Slick-C HM=0 MF=2293856 TL=0 MLL=0 ASE=0 LNL=6 LCF=0 CAPS=0 E=0 ESBU2=0 CL="" SC="" SCE= SCU=
   4:   D:\dev\ccm\projects\
   5:   0
   p_window_id: 5
   p_object: OI_FORM
   p_name:
restore.ex 1062 restore:restore2(,D:\dev\ccm\projects\,1,1)   p_window_id: 5   p_object: OI_FORM   p_name:
restore.ex 435 restore(,202,D:\dev\ccm\projects\,1,1)   p_window_id: 5   p_object: OI_FORM   p_name:
wkspace.ex 4874 workspace_open(D:\dev\ccm\projects\DBB0001.vpw,,,1,1)   p_window_id: 200 (invalid)
Adding "say" statements to the code shows that it's the _MDIChildGetWindow call that's failing. So, my question is; at what point is it OK to use that method on the _mdi.p_child object?

This is my resize.e
Code: [Select]
#include "slick.sh"
/* Macro that will automatically set all files that are opened to a specified size (see command "_buffer_add_resize()" comments for manual option.).

To use this macro:
1) the user can specify a window width, using the "Vertical line column" on the "Tools | Configuration | General", "General" tab.

-- OR --

2) the user can specify a window size for "_mdi.pchild.p_width" : please note that "Vertical line column" value must be zero (0) in order to use this option

-----------------

To change the window height, specify a different value for "_mdi.p_child.p_height" below.

Also, to specify a different location for opening the window, in the editor, change the values of "_mdi.p_child.p_x" and "_mdi.p_child.p_y" below.

To load the 'resize.e' macro file:

 *  Select "Macro | Load Module"
 *  Choose the 'resize.e' macro file from the browse.
 *  Click on the "Open" button
 *  You will see the message "Module(s) loaded" on the editor's message line.
*/

int windowIDs[];

void Trace( _str saystring )
{
   say( saystring );
}

_command resize_window( _str doall = "" ) name_info(',' VSARG2_MACRO | VSARG2_REQUIRES_EDITORCTL | VSARG2_MARK | VSARG2_READ_ONLY)
{
   int numWindows  = 0;
   int winWidthAdj = 55;
   int winOffsetX  = 20;
   int newHeight   = 0;
   int newWidth    = 0;

   if ( p_window_state :== 'M' )
   {
      p_window_state = 'N';
   }

   Trace( "*** Begin " :+ _date( 'I' ) :+ ' ' :+ _time( 'L' ) :+ " ***" );
   Trace( "Parameter DOALL<" :+ doall :+ ">" );
   Trace( "p_window_id<" :+ p_window_id :+ ">" );

   //
   // If the ALL paramter was passed on the command (entered manually) get the number of
   // windows (buffers). Otherwise process just the window being opened.
   //
   if ( "ALL" == upcase( doall ) )
   {
      GetListOfWindows( numWindows );
   }
   else
   {
      windowIDs[0] = _mdi.p_child;
      numWindows   = 1;
   }

   //
   // Establish the new window height.
   //
   int height = _default_option( VSOPTION_NEW_WINDOW_HEIGHT );

   if ( height < 1 )
   {
      typeless junk = 0;
      int mdiclient_width = 0, mdiclient_height = 0;

      _mdi._MDIClientGetWindow( junk, junk, mdiclient_width, mdiclient_height );
      Trace("_MDIClientGetWindow() width<" :+ mdiclient_width :+ "> height<" :+ mdiclient_height :+ ">");

      newHeight = mdiclient_height;
   }
   else
   {
      newHeight = height;
   }

   //int startWindowID = p_window_id;
   int i;

   for ( i = 0; i < numWindows; i++ )
   {
      int  curChild = windowIDs[i];
      _str bufName  = curChild.p_buf_name;
      Trace( "curChild<" :+ curChild :+ ">" );

      int ftpSys = pos( '\ftp\', bufName );

      if ( ftpSys )
      {
         parse bufName with drv ':\' . '\ftp\' sys '\' q1 '.' q2 '.' q3 '\' mbr

         bufName = drv :+ ":\\" :+ q1 :+ "\\" :+ q2 :+ "\\" :+ q3 :+ "\\" :+ mbr :+ ".mf"
      }

      int lastDot = lastpos( '.', bufName );

      boolean fAdjust = true;

      if ( lastDot )
      {
         Trace( "bufName<" :+ bufName :+ ">" );

         _str ext = substr( bufName, lastDot + 1 );

         int width=_default_option('R');

         //
         // Check if the extension is one we want to set a Vertical Line Column for.
         //

         switch ( ext ) {
         case "c"   :
         case "e"   :
         case "h"   :
         case "cpp" :
         case "xml" :
         case "xsd" :
            _default_option('R', 100);
            width=_default_option('R');

            newWidth = 760;

            break;
         case "mf"     :  // mainframe file
         case "asm"    :
         case "mac"    :
         case "gml"    :
         case "exec"   :
         case "gmlinc" :
         case "inc"    :
         case "pasm"   :
         case "pc"     :
         case "pcc"    :
            _default_option('R', 80);
            width=_default_option('R');

            break;

         default:
            fAdjust = false;
            Trace("Unknown extension<" :+ ext :+ ">");
         }

         if ( fAdjust ) //&& curChild > 100 )
         {
            int curX = 0, curY = 0, curWidth = 0, curHeight = 0;

            Trace( "Prior to _MDIChildGetWindow call" );
            curChild._MDIChildGetWindow( curX, curY, curWidth, curHeight );
            Trace( "curX<" :+ curX :+ "> curY<" :+ curY :+ "> curWidth<" :+ curWidth :+ "> curHeight<" :+ curHeight :+ '>' );

            if ( width )
            {
               message( "Resizing file " :+ bufName );

               newWidth = width * curChild.p_font_width + winWidthAdj;

               Trace("newWidth<" :+ newWidth :+ ">");

               curChild._MDIChildSetWindow( curX, curY, newWidth, newHeight );
            }
         }
      }
   }

   Trace( "*** End " :+ _date( 'I' ) :+ ' ' :+ _time( 'L' ) :+ " ***" );
}

void GetListOfWindows( int &numwins )
{
int StartWindowID = p_window_id;
int lastwindow_id;
int done = 0;
int index = 0;

   numwins = 0;

_prev_window 'HF';
lastwindow_id = p_window_id;
_next_window 'HF'

for ( ;; )
{
if ( p_window_id == lastwindow_id )
{
done=1;
}
if ( !(p_window_flags & (HIDE_WINDOW_OVERLAP) ) || arg(3) != '' )
{
windowIDs[index++] = p_window_id;
}

      _next_window  'HR';

      if ( done )
{
break;
}
}

numwins = index;
p_window_id = StartWindowID;

   Trace( "numwins<" :+ numwins :+ '>' );
}

/* "#if 1" -- will run this each time a file is opened
   "#if 0" -- will require user to run the command "_buffer_add_resize" manually
   (ie. bind to a key or from the Visual SlickEdit command line)
 */

#if 1
void _buffer_add_resize()
{
   if ( def_one_file != '' ) {
      resize_window();
   }
}
#endif

TxDot

  • Community Member
  • Posts: 38
  • Hero Points: 0
Re: When does the _MDIChildGetWindow method become "fully active"?
« Reply #1 on: November 07, 2013, 12:32:02 PM »
Bump. Any SE folks on here that can answer my question? Please. Pretty please with a cherry on top.  ;D

chrisant

  • Senior Community Member
  • Posts: 1410
  • Hero Points: 131
Re: When does the _MDIChildGetWindow method become "fully active"?
« Reply #2 on: November 07, 2013, 06:55:20 PM »
This is an invalid call:

Code: [Select]
curChild._MDIChildGetWindow( curX, curY, curWidth, curHeight );

Can't call windowId._MDIChildGetWindow.
Must call _mdi._MDIChildGetWindow.

By the way, double clicking any line in the stack error window jumps to that exact spot in the code.  That might be easier than adding a bunch of say() statements.

TxDot

  • Community Member
  • Posts: 38
  • Hero Points: 0
Re: When does the _MDIChildGetWindow method become "fully active"?
« Reply #3 on: November 07, 2013, 07:38:23 PM »
Hmm, the macro works just fine once the Project is open when I enter it in the command line. It sure seems like a timing issue.

chrisant

  • Senior Community Member
  • Posts: 1410
  • Hero Points: 131
Re: When does the _MDIChildGetWindow method become "fully active"?
« Reply #4 on: November 08, 2013, 01:01:19 AM »
Yeah, sorry, I misread the line.

_MDIClientGetWindow is only valid on _mdi.
_MDIChildGetWindow is valid on a windowId.

Try using _post_call() to work around this.  I'm not sure I'd expect the window to be ready yet during an initial _add_buffer callback, and the _post_call function is typically a good way to handle this kind of situation.

Code: [Select]
/**
 * Posts a calls to the Slick-C&reg; function corresponding to name table
 * index, proc_index, and optional passes the first argument, arg1.  The
 * call is made after the editor returns to a message loop.  This function
 * should only be used under circumstances where an operation can not be
 * performed immediately.  The dialog editor uses this function to display
 * error message boxes during on_lost_focus events.  During the
 * on_got_focus and on_lost_focus events you can not display a dialog box.
 * Use find_index to get an index to a global function.
 *
 * @param pfnCallback         pointer to function to call
 * @param CallbackArgument    argument to pass to function
 *
 * @categories Miscellaneous_Functions
 */
int _post_call(typeless pfnCallback,_str CallbackArgument=null);

TxDot

  • Community Member
  • Posts: 38
  • Hero Points: 0
Re: When does the _MDIChildGetWindow method become "fully active"?
« Reply #5 on: November 08, 2013, 03:07:13 PM »
I changed the macro to use _post_call( resize_window ) which sorta works. I say sorta because all the windows appear to be "processed" (at least they're opened) but I still get errors. The error message only includes this line in the stack window;
resize.ex 81 resize_window()   p_window_id: 90   p_object: OI_FORM   p_name:
and it is followed by 4 (sometimes 2) message boxes (regardless of how many fields in the project are being opened) that says basically the same thing. I don't get the level of detail I originally reported. Double clicking the error line just says file resize.e not found. Maybe that's because I have the macro in my own directory and not the default location.

So, some progress but still not quite right.

chrisant

  • Senior Community Member
  • Posts: 1410
  • Hero Points: 131
Re: When does the _MDIChildGetWindow method become "fully active"?
« Reply #6 on: November 09, 2013, 11:11:48 PM »
Probably the reason SE finds the macro files for me is because in the VSLICK.INI file I set VSLICKINCLUDE, VSLICKMACROS, and VSLICKPATH to all include the directories where I keep my macros.  If you do that then I would expect clicking in the stack form to work (and probably various other things will work better as well).

Sorry I can't take a more hands-on approach to helping you debug the macro right now.

One thing I do see offhand is that resize_window with no arguments acts on the current window.  Did you make changes so the deferred calls via _post_call know which window to act on?