home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / ocl150a.zip / OCL / Source / OMenu.cpp < prev    next >
C/C++ Source or Header  |  1996-08-12  |  8KB  |  335 lines

  1. // OCL - OS/2 Class Library
  2. // (c) Cubus 1995
  3. // All Rights Reserved
  4. // OMenu.cpp
  5.  
  6. /*
  7.  * Redistribution and use in source and binary forms, with or without
  8.  * modification, are permitted provided that the following conditions
  9.  * are met:
  10.  * 1. Redistributions of source code must retain the above copyright
  11.  *    notice, this list of conditions and the following disclaimer.
  12.  * 2. Neither the name Cubus nor the name Team OCL may be used to
  13.  *    endorse or promote products derived from this software
  14.  *    without specific prior written permission.
  15.  * 3. See OCL.INF for a detailed copyright notice.
  16.  *
  17.  *              THIS SOFTWARE IS PROVIDED ``AS IS'' AND
  18.  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  19.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  20.  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  21.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  22.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  23.  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  24.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  25.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  26.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  27.  * SUCH DAMAGE.
  28.  */
  29.  
  30.  
  31. // $Header: W:/Projects/OCL/Source/rcs/OMenu.cpp 1.50 1996/08/11 23:49:23 B.STEIN Release $
  32.  
  33. #define __OCL_SOURCE__
  34.  
  35. #define OINCL_OSTRING
  36. #define OINCL_BASE
  37.  
  38. #include <ocl.hpp>
  39. #include <OMenu.hpp>
  40. #include <OMessage.hpp>
  41.  
  42. #if defined(__EMX__)
  43.   template class OList<OMenuItem>;
  44. #endif
  45.  
  46.  
  47. // constructors
  48.  
  49. OMenu::OMenu(const ULONG id,
  50.              const HWND Parent,
  51.              const HWND Owner,
  52.              const pODynamicLib resLibrary)
  53.   : OWindow(id, 0, 0)
  54. {
  55.  if ((!resLibrary) || 
  56.      (!resLibrary->getLibHandle()) || 
  57.      (!Parent) || 
  58.      (!Owner))
  59.    throw OPMException(OCL::apierror(80, ERROR_BAD_ARGUMENTS), 0);
  60.  
  61.  parent = Parent;
  62.  owner  = Owner;
  63.  OMenu_resLibrary = resLibrary->getLibHandle(); 
  64.  
  65.  createOMenuObject();
  66. }
  67.  
  68.  
  69.  
  70. OMenu::OMenu(const ULONG id,
  71.              const HWND Parent,
  72.              const HWND Owner,
  73.              const HMODULE resLibrary)
  74.   : OWindow(id, 0, 0)
  75. {
  76.  if ((!Parent) || 
  77.      (!Owner))
  78.    throw OPMException(OCL::apierror(81, ERROR_BAD_ARGUMENTS), 0);
  79.  
  80.  parent = Parent;
  81.  owner  = Owner;
  82.  
  83.  OMenu_resLibrary = resLibrary; 
  84.  
  85.  createOMenuObject();
  86. }
  87.  
  88.  
  89. OMenu::OMenu(const ULONG id,
  90.              const OWindow& Parent,
  91.              const OWindow& Owner,
  92.              const pODynamicLib resLibrary)
  93.   : OWindow(id, 0, 0)
  94. {
  95.  if ((!resLibrary) || 
  96.      (!resLibrary->getLibHandle()) || 
  97.      (!Parent.hwnd) || 
  98.      (!Owner.hwnd))
  99.    throw OPMException(OCL::apierror(82, ERROR_BAD_ARGUMENTS), 0);
  100.  
  101.  parent = Parent.hwnd;
  102.  owner  = Owner.hwnd;
  103.  
  104.  OMenu_resLibrary = resLibrary->getLibHandle(); 
  105.  
  106.  createOMenuObject();
  107. }
  108.  
  109.  
  110. OMenu::OMenu(const ULONG id,
  111.              const OWindow& Parent,
  112.              const OWindow& Owner,
  113.              const HMODULE resLibrary)
  114.   : OWindow(id, 0, 0)
  115. {
  116.  if ((!Parent.hwnd) || 
  117.      (!Owner.hwnd))
  118.    throw OPMException(OCL::apierror(83, ERROR_BAD_ARGUMENTS), 0);
  119.  
  120.  parent = Parent.hwnd;
  121.  owner  = Owner.hwnd;
  122.  
  123.  OMenu_resLibrary = resLibrary; 
  124.  
  125.  createOMenuObject();
  126. }
  127.  
  128.  
  129. OMenu::OMenu(const ULONG id,
  130.              const pOWindow Parent,
  131.              const pOWindow Owner,
  132.              const pODynamicLib resLibrary)
  133.   : OWindow(id, 0, 0)
  134. {
  135.  if ((!resLibrary) || 
  136.      (!resLibrary->getLibHandle()) || 
  137.      (!Parent) ||
  138.      (!Parent->hwnd) ||
  139.      (!Owner) || 
  140.      (!Owner->hwnd))
  141.    throw OPMException(OCL::apierror(84, ERROR_BAD_ARGUMENTS), 0);
  142.  
  143.  parent = Parent->hwnd;
  144.  owner  = Owner->hwnd;
  145.  
  146.  OMenu_resLibrary = resLibrary->getLibHandle(); 
  147.  
  148.  createOMenuObject();
  149. }
  150.  
  151.  
  152. OMenu::OMenu(const ULONG id,
  153.              const pOWindow Parent,
  154.              const pOWindow Owner,
  155.              const HMODULE resLibrary)
  156.   : OWindow(id, 0, 0)
  157. {
  158.  if ((!Parent) ||
  159.      (!Parent->hwnd) ||
  160.      (!Owner) || 
  161.      (!Owner->hwnd))
  162.    throw OPMException(OCL::apierror(85, ERROR_BAD_ARGUMENTS), 0);
  163.  
  164.  parent = Parent->hwnd;
  165.  owner  = Owner->hwnd;
  166.  
  167.  OMenu_resLibrary = resLibrary; 
  168.  
  169.  createOMenuObject();
  170. }
  171.  
  172.  
  173. // destructor
  174.  
  175. OMenu::~OMenu()
  176.   {}
  177.  
  178.  
  179. PSZ OMenu::isOfType() const
  180.  return("OMenu"); 
  181. }
  182.  
  183.  
  184. // members
  185.  
  186. OMenu& OMenu::createOMenuObject()
  187. {
  188.  hwnd = WinLoadMenu(parent, OMenu_resLibrary, res);
  189.  
  190.  if (!hwnd)
  191.    throw OPMException(OCL::error(86), 0);
  192.  
  193.  setOwner(owner);
  194.  return(*this);
  195. }
  196.    
  197.  
  198. BOOL OMenu::isEnabled(const ULONG item)
  199. {
  200.  return(((BOOL)WinSendMsg(hwnd, 
  201.                           MM_QUERYITEMATTR, 
  202.                           MPFROM2SHORT(item, TRUE), 
  203.                           MPFROMSHORT(MIA_DISABLED)))!=TRUE);
  204. }
  205.  
  206. BOOL OMenu::isChecked(const ULONG item)
  207. {
  208.  return((BOOL)WinSendMsg(hwnd, 
  209.                          MM_QUERYITEMATTR, 
  210.                          MPFROM2SHORT(item, TRUE), 
  211.                          MPFROMSHORT(MIA_CHECKED)));
  212. }
  213.  
  214.  
  215. OMenu& OMenu::insertItem(const ULONG insertAfter, const pOMenuItem item)
  216. {
  217.  return(*this);
  218. }
  219.  
  220. OMenu& OMenu::insertItemList(const ULONG insertAfter, const plOMenuItem items)
  221. {
  222.  return(*this);
  223. }
  224.  
  225. OMenu& OMenu::removeItem(const ULONG item)
  226. {
  227.  return(*this);
  228. }
  229.  
  230. OMenu& OMenu::removeItemList(OList<ULONG>& items)
  231. {
  232.  return(*this);
  233. }
  234.  
  235. OMenu& OMenu::removeItemList(const ULONG items[], const ULONG elements)
  236. {
  237.  return(*this);
  238. }
  239.  
  240.  
  241. OMenu& OMenu::enableItem(const ULONG item, BOOL state)
  242. {
  243.  if (!(BOOL)WinSendMsg(hwnd, MM_SETITEMATTR, 
  244.                        MPFROM2SHORT(item, TRUE), 
  245.                        MPFROM2SHORT(MIA_DISABLED, state ? ~MIA_DISABLED : MIA_DISABLED)))
  246.    throw OPMException(OCL::error(87), 0);
  247.  return(*this);
  248. }
  249.  
  250. OMenu& OMenu::enableItemList(OList<ULONG>& items, BOOL state)
  251. {
  252.  PULONG temp = items.getFirst();
  253.  
  254.  while(temp) {
  255.    enableItem(*temp, state);
  256.    temp = items.getNext(); }
  257.  return(*this);
  258. }
  259.  
  260. OMenu& OMenu::enableItemList(const ULONG items[], const ULONG elements, BOOL state)
  261. {
  262.  for(ULONG step = 0; step < elements; step++)
  263.    enableItem(items[step], state);
  264.  
  265.  return(*this);
  266. }
  267.  
  268.  
  269. OMenu& OMenu::checkItem(const ULONG item, BOOL state)
  270. {
  271.  if (!(BOOL)WinSendMsg(hwnd, MM_SETITEMATTR, 
  272.                        MPFROM2SHORT(item, TRUE), 
  273.                        MPFROM2SHORT(MIA_CHECKED, state ? MIA_CHECKED : ~MIA_CHECKED)))
  274.    throw OPMException(OCL::error(88), 0);
  275.  return(*this);
  276. }
  277.  
  278. OMenu& OMenu::checkItemList(OList<ULONG>& items, BOOL state)
  279. {
  280.  PULONG temp = items.getFirst();
  281.  
  282.  while(temp) {
  283.    checkItem(*temp, state);
  284.    temp = items.getNext(); }
  285.  
  286.  return(*this);
  287. }
  288.  
  289.  
  290. OMenu& OMenu::checkItemList(const ULONG items[], const ULONG elements, BOOL state)
  291. {
  292.  for(ULONG step = 0; step < elements; step++)
  293.    checkItem(items[step], state);
  294.  
  295.  return(*this);
  296. }
  297.  
  298.  
  299. OMenu& OMenu::setItemText(const ULONG item, PCSZ text)
  300. {
  301.  if(!WinSendMsg(hwnd, MM_SETITEMTEXT, MPFROMSHORT(item), MPFROMP(text)))
  302.    throw OPMException(OCL::error(89), 0);
  303.  
  304.  return(*this);
  305. }
  306.  
  307.  
  308.  
  309. OMenu& OMenu::setItemText(const ULONG item, pOString text)
  310. {
  311.  if (!text)
  312.    throw OPMException(OCL::apierror(89, ERROR_BAD_ARGUMENTS), 0);
  313.  setItemText(item, text->getText());
  314.  
  315.  return(*this);
  316. }
  317.  
  318.  
  319. OMenu& OMenu::setItemText(const ULONG item, const ULONG resID)
  320. {
  321.  OString temp(CCHMAXPATH*2);
  322.  
  323.  if (!WinLoadString(OApp::current().anchor(),
  324.                     OMenu_resLibrary, resID,
  325.                     CCHMAXPATH*2, temp))
  326.    throw OPMException(OCL::error(90), 0);
  327.  
  328.  return(setItemText(item, temp)); 
  329. }
  330.  
  331.  
  332.  
  333. // end of source
  334.