home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c083 / 19.ddi / OWLINC.PAK / VBXCTL.H < prev    next >
Encoding:
C/C++ Source or Header  |  1993-12-02  |  11.9 KB  |  456 lines

  1. //----------------------------------------------------------------------------
  2. // ObjectWindows - (C) Copyright 1993 by Borland International
  3. //   include\owl\vbxctl.h
  4. //   Defines TVbxControl and associated classes
  5. //----------------------------------------------------------------------------
  6. #if !defined(__OWL_VBXCTL_H)
  7. #define __OWL_VBXCTL_H
  8.  
  9. #if !defined(__OWL_CONTROL_H)
  10.   #include <owl\control.h>
  11. #endif
  12. #if !defined(__BIVBX_H)
  13.   #include <bivbx.h>
  14. #endif
  15.  
  16. //
  17. //  class TBIVbxLibrary
  18. //  ----- -------------
  19. //
  20. class _OWLCLASS TBIVbxLibrary : virtual public TModule {
  21.   public:
  22.     TBIVbxLibrary();
  23.    ~TBIVbxLibrary();
  24. };
  25.   
  26. //
  27. //  class TVbxEventHandler
  28. //  ----- ----------------
  29. //
  30. class _OWLCLASS TVbxEventHandler : virtual public TEventHandler {
  31.   protected:
  32.     LRESULT  EvVbxDispatch(WPARAM wp, LPARAM lp);
  33.  
  34.   DECLARE_RESPONSE_TABLE(TVbxEventHandler);
  35. };
  36.  
  37. //
  38. //  class TVbxControl
  39. //  ----- -----------
  40. //
  41. class _OWLCLASS TVbxControl : public TControl, public TVbxEventHandler {
  42.   public:
  43.     TVbxControl(TWindow*        parent,
  44.                 int             id,
  45.                 const char far* vbxName,
  46.                 const char far* vbxClass,
  47.                 const char far* title,
  48.                 int             x,
  49.                 int             y,
  50.                 int             w,
  51.                 int             h,
  52.                 long            initLen = 0,
  53.                 void far*       initData = 0,
  54.                 TModule*        module = 0);
  55.  
  56.     TVbxControl(TWindow* parent, int resourceId, TModule* module = 0);
  57.    ~TVbxControl();
  58.  
  59.     void SetupWindow();
  60.  
  61.     LRESULT EvDefaultProcessing(WPARAM, LPARAM) { return DefaultProcessing(); }
  62.  
  63.     // properties
  64.     int GetNumProps();
  65.     int GetPropIndex(const char far* name);
  66.     const char far* GetPropName(int propIndex);
  67.     int GetPropType(int propIndex);
  68.     int GetPropType(char far* name);
  69.     BOOL IsArrayProp(int propIndex);
  70.     BOOL IsArrayProp(char far* name);
  71.  
  72.     // get properties by index
  73.     BOOL GetProp(int propIndex, int& value, int arrayIndex=-1);
  74.     BOOL GetProp(int propIndex, long& value, int arrayIndex=-1);
  75.     BOOL GetProp(int propIndex, ENUM& value, int arrayIndex=-1);
  76.     BOOL GetProp(int propIndex, HPIC& value, int arrayIndex=-1);
  77.     BOOL GetProp(int propIndex, float& value, int arrayIndex=-1);
  78.     BOOL GetProp(int propIndex, string& value, int arrayIndex=-1);
  79.     BOOL GetProp(int propIndex, COLORREF& value, int arrayIndex=-1);
  80.  
  81.     // get properties by name
  82.     BOOL GetProp(const char far* name, int& value, int arrayIndex=-1);
  83.     BOOL GetProp(const char far* name, long& value, int arrayIndex=-1);
  84.     BOOL GetProp(const char far* name, ENUM& value, int arrayIndex=-1);
  85.     BOOL GetProp(const char far* name, HPIC& value, int arrayIndex=-1);
  86.     BOOL GetProp(const char far* name, float& value, int arrayIndex=-1);
  87.     BOOL GetProp(const char far* name, string& value, int arrayIndex=-1);
  88.     BOOL GetProp(const char far* name, COLORREF& value, int arrayIndex=-1);
  89.  
  90.     // set properties by index
  91.     BOOL SetProp(int propIndex, int value, int arrayIndex=-1);
  92.     BOOL SetProp(int propIndex, long value, int arrayIndex=-1);
  93.     BOOL SetProp(int propIndex, ENUM value, int arrayIndex=-1);
  94.     BOOL SetProp(int propIndex, HPIC value, int arrayIndex=-1);
  95.     BOOL SetProp(int propIndex, float value, int arrayIndex=-1);
  96.     BOOL SetProp(int propIndex, const string& value, int arrayIndex=-1);
  97.     BOOL SetProp(int propIndex, const char far* value, int arrayIndex=-1);
  98.     BOOL SetProp(int propIndex, COLORREF value, int arrayIndex=-1);
  99.  
  100.     // set properties by name
  101.     BOOL SetProp(const char far* name, int value, int arrayIndex=-1);
  102.     BOOL SetProp(const char far* name, long value, int arrayIndex=-1);
  103.     BOOL SetProp(const char far* name, ENUM value, int arrayIndex=-1);
  104.     BOOL SetProp(const char far* name, HPIC value, int arrayIndex=-1);
  105.     BOOL SetProp(const char far* name, float value, int arrayIndex=-1);
  106.     BOOL SetProp(const char far* name, const string& value, int arrayIndex=-1);
  107.     BOOL SetProp(const char far* name, const char far* value, int arrayIndex=-1);
  108.     BOOL SetProp(const char far*, COLORREF value, int arrayIndex=-1);
  109.  
  110.     // events
  111.     int GetNumEvents();
  112.     int GetEventIndex(const char far* name);
  113.     const char far* GetEventName(int eventIndex);
  114.     
  115.     // methods
  116.     BOOL Method(int method, long far* args);
  117.     BOOL AddItem(int index, const char far* item);
  118.     BOOL Drag(int action);
  119.     BOOL Move(long x, long y, long w, long h);
  120.     BOOL Refresh();
  121.     BOOL RemoveItem(int index);
  122.     
  123.     // control
  124.     HCTL GetHCTL() {return HCtl;}
  125.  
  126.   protected:
  127.     char far* GetClassName();
  128.     void PerformCreate(int menuOrId);
  129.     BOOL GetVBXProperty(int propIndex, void far *value, int arrayIndex=-1);
  130.     BOOL SetVBXProperty(int propIndex, LONG value, int arrayIndex=-1);
  131.     
  132.   private:
  133.     HCTL HCtl;
  134.     char far* VbxName;
  135.     char far* VbxClass;
  136.     long InitLen;
  137.     void far* InitData;
  138.  
  139.   DECLARE_RESPONSE_TABLE(TVbxControl);
  140.   DECLARE_CASTABLE;
  141. };
  142.  
  143.  
  144. //
  145. // Response table macros for VBX events
  146. //
  147. #define EV_VBXEVENTNAME(id,name,method)\
  148.   {WM_VBXNAME,id,(TAnyDispatcher)name,(TMyPMF)VbxSig(&TMyClass::method)}
  149.  
  150. #define EV_VBXEVENTINDEX(id,event,method)\
  151.   {WM_VBXBASE+event,id,(TAnyDispatcher)::i_LPARAM_Dispatch,\
  152.   (TMyPMF)VbxSig(&TMyClass::method)}
  153.  
  154. //
  155. // WM_VBXFIREEVENT signature template
  156. //
  157. template <class T>
  158. inline void(T::*VbxSig(void(T::*pmf)(VBXEVENT FAR*))) (VBXEVENT FAR*)
  159. {
  160.   return pmf;
  161. }
  162.  
  163. //
  164. //  VBXDispatch - dispatch function to crack a WM_VBXFIREEVENT message and
  165. //  pass control to a pointer to member function.
  166. //
  167. LRESULT
  168. VBXDispatch(GENERIC& generic,
  169.             void    (GENERIC::*pmf)(VBXEVENT FAR*),
  170.             WPARAM   wParam,
  171.             LPARAM   lParam);
  172.  
  173.           
  174. //
  175. // TVbxControl Inlines
  176. //
  177.  
  178. inline int TVbxControl::GetNumProps()
  179. {
  180.   return ::VBXGetNumProps(HCtl);
  181. }
  182.  
  183. inline int TVbxControl::GetPropIndex(const char far* name)
  184. {
  185.   return ::VBXGetPropIndex(HCtl, name);
  186. }
  187.  
  188. inline const char far* TVbxControl::GetPropName(int propIndex)
  189. {
  190.   return ::VBXGetPropName(HCtl, propIndex);
  191. }
  192.  
  193. inline int TVbxControl::GetPropType(int propIndex)
  194. {
  195.   return ::VBXGetPropType(HCtl, propIndex);
  196. }
  197.  
  198. inline int TVbxControl::GetPropType(char far* name)
  199. {
  200.   return GetPropType(GetPropIndex(name));
  201. }
  202.  
  203. inline BOOL TVbxControl::IsArrayProp(int propIndex)
  204. {
  205.   return ::VBXIsArrayProp(HCtl, propIndex);
  206. }
  207.  
  208. inline BOOL TVbxControl::IsArrayProp(char far* name)
  209. {
  210.   return IsArrayProp(GetPropIndex(name));
  211. }
  212.  
  213.  
  214. // get properties by id
  215.  
  216. inline BOOL 
  217. TVbxControl::GetProp(int propIndex, int& value, int arrayIndex)
  218. {
  219.   return GetVBXProperty(propIndex, &value, arrayIndex);
  220. }
  221.  
  222. inline BOOL 
  223. TVbxControl::GetProp(int propIndex, long& value, int arrayIndex)
  224. {
  225.   return GetVBXProperty(propIndex, &value, arrayIndex);
  226. }
  227.  
  228. inline BOOL 
  229. TVbxControl::GetProp(int propIndex, ENUM& value, int arrayIndex)
  230. {
  231.   BOOL rv;
  232.   short temp;
  233.   rv = GetVBXProperty(propIndex, &temp, arrayIndex);
  234.   value = (ENUM) temp;
  235.   return rv;
  236. }
  237.  
  238. inline BOOL 
  239. TVbxControl::GetProp(int propIndex, HPIC& value, int arrayIndex)
  240. {
  241.   return GetVBXProperty(propIndex, &value, arrayIndex);
  242. }
  243.  
  244. inline BOOL 
  245. TVbxControl::GetProp(int propIndex, float& value, int arrayIndex)
  246. {
  247.   return GetVBXProperty(propIndex, &value, arrayIndex);
  248. }
  249.  
  250. inline BOOL 
  251. TVbxControl::GetProp(int propIndex, COLORREF& value, int arrayIndex)
  252. {
  253.   return GetVBXProperty(propIndex, &value, arrayIndex);
  254. }
  255.  
  256. // get properties by name
  257.  
  258. inline BOOL 
  259. TVbxControl::GetProp(const char far* name, int& value, int arrayIndex)
  260. {
  261.   return GetProp(GetPropIndex(name), value, arrayIndex);
  262. }
  263.  
  264. inline BOOL 
  265. TVbxControl::GetProp(const char far* name, long& value, int arrayIndex)
  266. {
  267.   return GetProp(GetPropIndex(name), value, arrayIndex);
  268. }
  269.  
  270. inline BOOL 
  271. TVbxControl::GetProp(const char far* name, ENUM& value, int arrayIndex)
  272. {
  273.   return GetProp(GetPropIndex(name), value, arrayIndex);
  274. }
  275.  
  276. inline BOOL 
  277. TVbxControl::GetProp(const char far* name, HPIC& value, int arrayIndex)
  278. {
  279.   return GetProp(GetPropIndex(name), value, arrayIndex);
  280. }
  281.  
  282. inline BOOL 
  283. TVbxControl::GetProp(const char far* name, float& value, int arrayIndex)
  284. {
  285.   return GetProp(GetPropIndex(name), value, arrayIndex);
  286. }
  287.  
  288. inline BOOL 
  289. TVbxControl::GetProp(const char far* name, string& value, int arrayIndex)
  290. {
  291.   return GetProp(GetPropIndex(name), value, arrayIndex);
  292. }
  293.  
  294. inline BOOL 
  295. TVbxControl::GetProp(const char far* name, COLORREF& value, int arrayIndex)
  296. {
  297.   return GetProp(GetPropIndex(name), value, arrayIndex);
  298. }
  299.  
  300. // set properties by id
  301.  
  302. inline BOOL 
  303. TVbxControl::SetProp(int propIndex, int value, int arrayIndex)
  304. {
  305.   return SetVBXProperty(propIndex, value, arrayIndex);
  306. }
  307.  
  308. inline BOOL 
  309. TVbxControl::SetProp(int propIndex, long value, int arrayIndex)
  310. {
  311.   return SetVBXProperty(propIndex, value, arrayIndex);
  312. }
  313.  
  314. inline BOOL 
  315. TVbxControl::SetProp(int propIndex, HPIC value, int arrayIndex)
  316. {
  317.   return SetVBXProperty(propIndex, value, arrayIndex);
  318. }
  319.  
  320. inline BOOL 
  321. TVbxControl::SetProp(int propIndex, ENUM value, int arrayIndex)
  322. {
  323.   return SetVBXProperty(propIndex, (long)value, arrayIndex);
  324. }
  325.  
  326. inline BOOL
  327. TVbxControl::SetProp(int propIndex, float value, int arrayIndex)
  328. {
  329.   return SetVBXProperty(propIndex, *((long*)&value), arrayIndex);
  330. }
  331.  
  332. inline BOOL
  333. TVbxControl::SetProp(int propIndex, const string& value, int arrayIndex)
  334. {
  335.   return SetVBXProperty(propIndex, long(value.c_str()), arrayIndex);
  336. }
  337.  
  338. inline BOOL
  339. TVbxControl::SetProp(int propIndex, const char far* value, int arrayIndex)
  340. {
  341.   return SetVBXProperty(propIndex, (long)value, arrayIndex);
  342. }
  343.  
  344. inline BOOL
  345. TVbxControl::SetProp(int propIndex, COLORREF value, int arrayIndex)
  346. {
  347.   return SetVBXProperty(propIndex, (long)value, arrayIndex);
  348. }
  349.  
  350. // set properties by name
  351.  
  352. inline BOOL
  353. TVbxControl::SetProp(const char far* name, int value, int arrayIndex)
  354. {
  355.   return SetProp(GetPropIndex(name), value);
  356. }
  357.  
  358. inline BOOL 
  359. TVbxControl::SetProp(const char far* name, long value, int arrayIndex)
  360. {
  361.   return SetProp(GetPropIndex(name), value);
  362. }
  363.  
  364. inline BOOL 
  365. TVbxControl::SetProp(const char far* name, ENUM value, int arrayIndex)
  366. {
  367.   return SetProp(GetPropIndex(name), value);
  368. }
  369.  
  370. inline BOOL 
  371. TVbxControl::SetProp(const char far* name, HPIC value, int arrayIndex)
  372. {
  373.   return SetProp(GetPropIndex(name), value);
  374. }
  375.  
  376. inline BOOL 
  377. TVbxControl::SetProp(const char far* name, float value, int arrayIndex)
  378. {
  379.   return SetProp(GetPropIndex(name), value);
  380. }
  381.  
  382. inline BOOL 
  383. TVbxControl::SetProp(const char far* name, const string& value, int arrayIndex)
  384. {
  385.   return SetProp(GetPropIndex(name), value.c_str());
  386. }
  387.  
  388. inline BOOL 
  389. TVbxControl::SetProp(const char far* name, const char far* value, int arrayIndex)
  390. {
  391.   return SetProp(GetPropIndex(name), value);
  392. }
  393.  
  394. inline BOOL 
  395. TVbxControl::SetProp(const char far* name, COLORREF value, int arrayIndex)
  396. {
  397.   return SetProp(GetPropIndex(name), value);
  398. }
  399.  
  400.  
  401. inline int 
  402. TVbxControl::GetNumEvents()
  403. {
  404.   return ::VBXGetNumEvents(HCtl);
  405. }
  406.  
  407. inline int 
  408. TVbxControl::GetEventIndex(const char far* name)
  409. {
  410.   return ::VBXGetEventIndex(HCtl, name);
  411. }
  412.  
  413. inline const char far*
  414. TVbxControl::GetEventName(int eventIndex)
  415. {
  416.   return ::VBXGetEventName(HCtl, eventIndex);
  417. }
  418.  
  419. inline BOOL 
  420. TVbxControl::Method(int method, long far* args)
  421. {
  422.   return ::VBXMethod(HCtl, method, args);
  423. }
  424.  
  425. inline BOOL 
  426. TVbxControl::AddItem(int index, const char far* item)
  427. {
  428.   return ::VBXMethodAddItem(HCtl, index, item);
  429. }
  430.  
  431. inline BOOL
  432. TVbxControl::Drag(int action)
  433. {
  434.   return ::VBXMethodDrag(HCtl, action);
  435. }
  436.  
  437. inline BOOL
  438. TVbxControl::Move(long x, long y, long w, long h)
  439. {
  440.   return ::VBXMethodMove(HCtl, x, y, w, h);
  441. }
  442.  
  443. inline BOOL
  444. TVbxControl::Refresh()
  445. {
  446.   return ::VBXMethodRefresh(HCtl);
  447. }
  448.  
  449. inline BOOL
  450. TVbxControl::RemoveItem(int index)
  451. {
  452.   return ::VBXMethodRemoveItem(HCtl, index);
  453. }
  454.  
  455. #endif  // __OWL_VBXCTL_H
  456.