(no subject)

(no subject)

Post by Doug Elevel » Wed, 19 Feb 1997 04:00:00

Can anyone help me make a C++ object for Allegro's Gui?  
I've got it basically working except for Allegro's do_dialog function
doesn't seem to want to give the the focus when the object says it
wants to have the focus.  The code is pretty self explanatory
and is strongly based on Allegro's EX13.C

Thanks in advance,

Doug Eleveld

------------------------CUT HERE------------------------
// Attempting to make a C++ object interface with the Allegro gui

// The do_dialog function does not want to give my object the focus
// My dialog_object class only works when I give myself the focus
// in the msg_gotfocus and msg_lostfocus member functions.
// You can uncomment the functions and move the mouse over the object
// to see the diffrence
// For some reason, the do_dialog function doesn't want to do it for me
// Anyone have any ideas what I am doing wrong here?

// This code is extensively based on Allegros' ex13.c
// Trying to make a C++ gui object interface with the allegro do_dialog
// So I removed a whole lot of stuff from ex13.c and added a
// dialog_object
// class.  There is a box on the screen which should draw a diagonal
// line when it has the focus and be clear without the focus

#include <stdlib.h>
#include <stdio.h>
#include "allegro.h"

#include <assert.h>

class dialog_object
         :public DIALOG
        // This function calls the right member functions when used
        // an allegro gui procedure
        static int dispatch_message_proc (int, DIALOG*, int);

        // Ask about the object state
        bool has_focus (void) const { if(flags&D_GOTFOCUS) return true;
return false; }
        bool has_mouse (void) const { if(flags&D_GOTMOUSE) return true;
return false; }
        bool selected  (void) const { if(flags&D_SELECTED) return true;
return false; }

               // Message functions
               virtual void msg_start (void);
               virtual void msg_end (void);
               virtual void msg_draw (void);
               virtual void msg_click (void);
               virtual void msg_dclick (void);
               virtual void msg_key (void);
               virtual bool msg_char (const int);
               virtual bool msg_xchar (const int);
               virtual bool msg_wantfocus (void);
               virtual void msg_gotfocus (void);
               virtual void msg_lostfocus (void);
               virtual void msg_gotmouse (void);
               virtual void msg_lostmouse (void);
               virtual void msg_idle (void);
               virtual void msg_radio (const int);

        // Objects request redraw of dialog closings by setting
        // these variables and the dispatch_message_proc will
        // pass them along to the do_dialog procedure properly
               static bool request_redraw;
               static bool request_close;

        // Constructors and destructors
        dialog_object (const int, const int, const int, const int);
        virtual ~dialog_object (void);
// Static variables and functions
bool dialog_object::request_redraw = false;
bool dialog_object::request_close = false;

// The main dispatching function i.e. the interface between the C and C++
// object
int dialog_object::dispatch_message_proc (int msg, DIALOG *d, int c)
   // This conversion looks dangerous but actually it isnt since
   // it is a private function of the dialog_object and so it can only
   // be called from a dialog_object and so it can only be set as a
   // message procedure for the dialog through the dialog_object
   // So we know when this function is called, the DAILOG *d is
   // also a dialog_object and so we can use it to call the message
   // functions
   // for itself and the derived classes of dialog_object
   // dialog_object *object = (dialog_object*)(d->dp);

   // Convert the allegro message to a call of a member function
         if(object->msg_char(c)==true) return D_USED_CHAR;
         if(object->msg_xchar(c)==true) return D_USED_CHAR;
         if(object->msg_wantfocus()==true) return D_WANTFOCUS;

// Here is the part that I don't understand
// The do_dialog function does not want to give my object the focus

                // Shouldn't the do_dialog function have given me the
                // focus
                // before calling this ?

        // I think this assertion should fail but it doesn't !!!!


         // Just ignore an unknown message
   // Check if any of the functions asked for a redraw or a close of the
   // dialog
      dialog_object::request_redraw = false;
      return D_REDRAW;
      dialog_object::request_close = false;
      return D_CLOSE;

   return D_O_K;
// Constructor
dialog_object::dialog_object (const int rx, const int ry, const int rw,
const int rh)
   // Set the dimensions
   x = rx;
   y = ry;
   w = rw;
   h = rh;

   // Set an all empty DIALOG
   key = 0;
   flags = 0;
   d1 = d2 = 0;

   // Quick setup of some colours
   fg = gui_fg_color;
   bg = gui_bg_color;

   // Setup the C++ message dispatching function
   proc = &dispatch_message_proc;

   // For C++ objects dp is the pointer to the internal dialog
   dp = this;
// Destructor
dialog_object::~dialog_object (void)
// Basic message passing functions

// Initialization of the dialog
void dialog_object::msg_start (void)      { }

// De-initialization of the dialog
void dialog_object::msg_end (void)        { }

// Tell the object to draw itself
void dialog_object::msg_draw (void)
   if((flags)&D_GOTFOCUS) line(screen,x,y,x+w,y+h,255);
   else line(screen,x,y,x+w,y+h,0);

// Tell the object to deal with a mouse click
void dialog_object::msg_click (void)      { }

// Tell the object to deal with a double click
void dialog_object::msg_dclick (void)     { }

// Tell the object that a shortcut key was pressed
void dialog_object::msg_key (void)        { if(flags&D_EXIT) {
request_close = true; } }

// Tell the object that a key was pressed while it had the focus
// This should return true if the key was used
bool dialog_object::msg_char (const int)  { return false; }

// Tell the object that a key was pressed while it did noty have the
// This should return true if the key was used
bool dialog_object::msg_xchar (const int) { return false; }

// Ask the object if they want the focus
bool dialog_object::msg_wantfocus (void)  { return true; }

// ??????????????????????????????????????????????????????????????????

// My dialog_object class only works when I give myself the focus
// in the msg_gotfocus and msg_lostfocus member functions.
// For some reason, the do_dialog function doesn't want to do it for me
// If you uncomment the stuff in the msg_gotfocus and msg_lostfocus
// member function then it will work.  Why doesn't Allegro do this for
// me?

// Anyone have any ideas what I am doing wrong here?

// Tell the object that the got or lost the focus
void dialog_object::msg_gotfocus (void)   { /*flags|=D_GOTFOCUS; */  }
void dialog_object::msg_lostfocus (void)  { /*flags&=~D_GOTFOCUS;*/  }

// ????????????????????????????????????????????????????????????????????

// Tell the object that they got or lost the mouse
void dialog_object::msg_gotmouse (void)   { }
void dialog_object::msg_lostmouse (void)  { }

// Tell the object that the object manager is bored
void dialog_object::msg_idle (void)       { }

// Deselect grouped radio buttons
void dialog_object::msg_radio (const int)       { }

// Declare the dialog object
dialog_object test_object = dialog_object(80,132,160,48);

// A test dialog for the dialog object
DIALOG the_dialog[] =
   /* (dialog proc)     (x)   (y)   (w)   (h)   (fg)  (bg)  (key) (flags)
 (d1)  (d2)  (dp) */
   { d_clear_proc,      0,    0,    192,  172,  255,  0,    0,    0,    
  0,    0,    NULL },
   { d_text_proc,       80,   32,   512,  48,   255,  0,    0,    0,    
  0,    0,    "There should be a line in the box when you move the mouse
into it" },
   { NULL,              0,    0,    0,    0,    0,    0,    0,    0,    
  0,    0,    NULL }


int main(void)
   /* initialise everything */
   set_gfx_mode(GFX_VESA1, 640, 480, 0, 0);

   /* do the dialog */
   do_dialog(the_dialog, 2);



1. 2nd RFD: comp.os.nos.lanman

This is a second posting of the Request For Discussion for a newsgroup
discussing Lan Manager based/derived networking.  Of note is a new name
proposed for the group.

Request For Discussion (RFD) for comp.os.nos.lanman  (was comp.sys.lanman)


         Create an UNMODERATED Usenet newsgroup comp.os.nos.lanman


         A group for the discussion of Microsoft Lan Manager networking and
related products including IBM Lan Server, 3Com 3+Open, Syntax, Pathworkds,
and other OEM products.  This forum is primarily for discussing installation,
maintenance, and administration of Microsoft Lan Manager based networks and
workstations under various operating systems, including DOS, Macintosh, UNIX,
OS/2, Windows NT, and Windws for Workgroups.


         Microsoft Lan Manager and numerous OEM variants are widely used in
the business and academic environment.  There already exists a mailing list
(LANMAN-L) devoted to Microsoft Lan Manager, and various newsgroups that
occasionally see Lan Manager related traffic, including comp.dcom.lan.misc,
comp.os.os2.networking, comp.sys.novell, comp.os.ms-windows.programmer.win32,
comp.sys.hp, comp.protocols.* and several others.  Creating a single Usenet
newsgroup comp.sys.lanman will make a single place where Lan Manager network
administrators and users can share and obtain information.

         Additionaly, as operating systems such as MS Windows NT and IBM OS/2
2.0 gain popularity, interest in Lan Manager related networking will grow.
The networking capabilities of MS Windows/NT will be an implementation of
Microsoft Lan Manager, and IBM's Lan Server family of products (including the
forthcoming OS/2 Peer Services) is derived from Microsoft Lan Manager.  Other
OEM manufacturers of Lan Manager derived products include 3Com and HP.

        One issue remaining to be resolved is whether or not the existing
mailing list LANMAN-L will be gatewayed to comp.sys.lanman if it is created.
The administrator of the site hosting LANMAN-L has expressed his willingness
to create such a gateway, though final word, of course, rests with the list's

|       During the discussion up to this point, it has become apparent that a
|name outside the comp.sys hierarchy would be more appropriate.  In light of
|this, the name of the proposed group has changed from comp.sys.lanman to
|comp.os.nos.lanman.  It is hoped that the comp.sys.nos.* hierarchy can
|accomodate other Network Operating System discussion groups in the future.
|This RFD _does_not_ propose renaming or creating any additional groups.  

Albert Crosby          | There are actually THREE things certain in this life:

 or AL.CROSBY on GENIE |   Death, Taxes, and Parking Tickets.
1 501 575 4452         |
Microcomputer and Network Support-UA College of Agriculture and Home Economics

2. nfs problem over WAN. Help !!!!!!!

3. Changing serial nos of floppys

4. FS: (US) DKB Megachip - $75.00

5. Running Ethernet without a nos? How?

6. Fixpack for OS/2 2.1

7. Any one tried KA9Q TCP/IP NOS ?

8. Windows Forms Closes Automatically.

9. Net/NOS Systems

10. Artprice : join our Affiliates - rejoignez nos Affilies

11. 3 or 4 interesting questions (I know this subject stinks, m'enfin!)

12. (no subject)