⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 xsmotifwindow.c

📁 Wxpython Implemented on Windows CE, Source code
💻 C
📖 第 1 页 / 共 5 页
字号:
            {
               _pressed = True;
               _redraw ( );
               break;
            }
            case 2:
            {
               XsMoveOutline move (_win->base ( ));

// Start the move

               if (move.go ( ) != False)
               {

// Relocate the window      
   
                  _win->setPosition (move.x ( ), move.y ( ));
               }
               break;
            }
            case 3:
            {
               _win->popupMenu ( );
               break;
            }
         }
         break;
      }         
      case ButtonRelease:
      {
         switch (event->xbutton.button)
         {
            case 1:
            case 2:
            {
               _pressed = False;
               _redraw ( );

               _win->raise ( );
               break;
            }
         }
         break;
      }
      case MotionNotify:
      {
         XsMoveOutline move (_win->base ( ));

// Start the move

         if (move.go ( ) != False)
         {

// Relocate the window      
   
            _win->setPosition (move.x ( ), move.y ( ));

// Redraw the title bar

            _pressed = False;
            _redraw ( );
         }
         break;
      }
   }
}

// _map

void _XsMotifTitle::_map ( )
{
   
// Call the base-class

   _XsMotifComponent::_map ( );

// Raise ourself
   
   XRaiseWindow (XtDisplay (_base), XtWindow (_base));
   
   unsigned long valuemask;
   XGCValues   values;
   Pixel foreground;
   Pixel background;

// Get the pixels

   XtVaGetValues (_win->base ( ), XmNforeground, &foreground, XmNbackground, &background, NULL);

// Create the font graphics context

   valuemask = GCForeground | GCBackground | GCGraphicsExposures | GCFont;

   values.foreground = foreground;
   values.background = background;
   values.font = _titleFont->fid;
   values.graphics_exposures = False;

   _fontGC = XtGetGC (_base, valuemask, &values);
}

// _configure

void _XsMotifTitle::_configure (XEvent *event)
{
   XConfigureEvent *ce = (XConfigureEvent*)event;
   
/*
   Check if window has been resized.  If so, generate an expose event
   to redraw its contents.
*/

   if ((_lastW != ce->width) || (_lastH != ce->height))
   {
      if ((_base != 0) && XtIsManaged (_base))
         XClearArea (XtDisplay (_base), XtWindow (_base), 0, 0, 0, 0, True);

      _lastW = ce->width;
      _lastH = ce->height;
   }
}

// _configureEventHandler

void _XsMotifTitle::_configureEventHandler (Widget, XtPointer clientData, XEvent *event, Boolean*)
{
   if (event->type == ConfigureNotify)
   {
      _XsMotifTitle *obj = (_XsMotifTitle*)clientData;
      obj->_configure (event);
   }
}

/*
   ----------------------------------------------------------------------------
   _XsMotifIcon
*/

XtResource _XsMotifIcon::_resourceList[] = {
   {
      "iconSize",
      "IconSize",
      XmRDimension,
      sizeof (Dimension),
      XtOffset (_XsMotifIcon*, _iconSize),
      XmRImmediate,
      (XtPointer)IconSize_
   },
   {
      "iconName",
      "IconName",
      XmRString,
      sizeof (String),
      XtOffset (_XsMotifIcon*, _iconName),
      XmRImmediate,
      NULL
   },
   {
      "iconFont",
      "IconFont",
      XmRFontStruct,
      sizeof (XFontStruct*),
      XtOffset (_XsMotifIcon*, _iconFont),
      XmRString,
      "-*-helvetica-bold-r-normal-*-12-*-*-*-*-*-iso8859-1"
   },
   {
      XmNiconX,
      XmCIconX,
      XmRPosition,
      sizeof (Position),
      XtOffset (_XsMotifIcon*, _iconX),
      XmRImmediate,
      (XtPointer)-1
   },      
   {
      XmNiconY,
      XmCIconY,
      XmRPosition,
      sizeof (Position),
      XtOffset (_XsMotifIcon*, _iconY),
      XmRImmediate,
      (XtPointer)-1
   }
};

// Constructor

_XsMotifIcon::_XsMotifIcon (const char *name, XsMotifWindow *win, Widget parent) :
   _XsMotifComponent (name, win, parent)
{
   
// Initialize

   _pixmapGC = 0;
   _fontGC = 0;

   _iconName = 0;
   _pixmap = 0;
   _freePixmap = False;
   
   _width = _height = 0;
   _placed = 0;
   
// Get resources
   
   _getResources (_resourceList, XtNumber (_resourceList));

// Copy icon name to local memory

   if (_iconName != 0)
   {
      char *tmp = new char[strlen (_iconName) + 1];
      strcpy (tmp, _iconName);
      _iconName = tmp;
   }

// Configure the icon

   XtVaSetValues (_base, XmNwidth, _iconSize, XmNheight, _iconSize, NULL);
}

// Destructor

_XsMotifIcon::~_XsMotifIcon ( )
{
   if (_fontGC)
      XtReleaseGC (_base, _fontGC);
      
   if (_pixmapGC)
      XtReleaseGC (_base, _pixmapGC);
      
   if (_freePixmap)
      XFreePixmap (XtDisplay (_base), _pixmap);

   delete [] _iconName;
}

// show

void _XsMotifIcon::show ( )
{

/*
   Configure the icon position.  Either use the position specified
   in the resource, or place the icon at the top-left corner of the
   window.
*/

   if (_placed == False)
   {
      Position x, y;
   
      if (_iconX == -1)
      {
         XtVaGetValues (_win->base ( ), XmNx, &x, NULL);
         if (x < 0)  x = 0;
         _iconX = x;
      }
      else
         x = _iconX;
      
      if (_iconY == -1)
      {
         XtVaGetValues (_win->base ( ), XmNy, &y, NULL);
         if (y < 0)  y = 0;
         _iconY = y;
      }
      else
         y = _iconY;
      
      XtVaSetValues (_base, XmNx, x, XmNy, y, NULL);

      _placed = True;
   }
   
// Call the base class

   _XsMotifComponent::show ( );
}

// setIconName

void _XsMotifIcon::setIconName (const char *iconName)
{
   assert (iconName != 0);

   delete [] _iconName;
   
   _iconName = new char[strlen (iconName) + 1];
   strcpy (_iconName, iconName);
}

// setPixmap

void _XsMotifIcon::setPixmap (Pixmap pixmap)
{
   assert (pixmap != 0);
   
// Free the existing pixmap (if necessary)

   if (_freePixmap)
   {
      XFreePixmap (XtDisplay (_base), _pixmap);
      _freePixmap = False;
   }
   
// Save the new pixmap

   _pixmap = pixmap;

// Get the pixmap width and height

   Window   dummy;
   int      xd, yd;
   unsigned int   uw, uh, ub, ud;
   
   XGetGeometry (XtDisplay (_base), _pixmap, &dummy, &xd, &yd, &uw, &uh, &ub, &ud);

   _width = uw;
   _height = uh;
}
   
// className

const char *_XsMotifIcon::className ( ) const
{
   return ("_XsMotifIcon");
}

// _componentDestroyed

void _XsMotifIcon::_componentDestroyed ( )
{
   
// Clear up the GCs

   if (_fontGC)
      XtReleaseGC (_base, _fontGC);

   if (_pixmapGC)
      XtReleaseGC (_base, _pixmapGC);

   if (_freePixmap)
      XFreePixmap (XtDisplay (_base), _pixmap);

   _fontGC = 0;
   _pixmapGC = 0;
   _freePixmap = 0;
   
// Call the base-class

   _XsMotifComponent::_componentDestroyed ( );
}
   
// _input

void _XsMotifIcon::_input (XEvent *event)
{
   static Time lastTime = (Time)0;
   
   switch (event->type)
   {
      case ButtonPress:
      {
         switch (event->xbutton.button)
         {
            case 1:
               break;

            case 2:
            {
               XsMoveOutline move (_base);

// Start the move

               if (move.go ( ) != False)
               {

// Relocate the window      
   
                  _win->setPosition (move.x ( ), move.y ( ));
               }
               break;
            }
            case 3:
            {
               _win->popupMenu ( );
               break;
            }               
         }
         break;
      }         
      case ButtonRelease:
      {
         switch (event->xbutton.button)
         {
            case 1:
            {

// Get double-click time

               int multiClick = XtGetMultiClickTime (XtDisplay (_base));

// Check for double-click

               if ((event->xbutton.time - lastTime) <= multiClick)
                  _win->restore ( );
               else
               {
                  lastTime = event->xbutton.time;
                  _win->raise ( );
               }
               break;
            }
         }
         break;
      }
      case MotionNotify:
      {
         XsMoveOutline  move (_base);

// Start the move

         if (move.go ( ) != False)
         {

// Relocate the icon
   
            _win->setPosition (move.x ( ), move.y ( ));
         }
         break;
      }
   }
}

// _expose

void _XsMotifIcon::_expose (XEvent *)
{
   if (_topShadowGC == 0) // JACS
     return;

   Dimension   iconHeight;
   Dimension   iconWidth;

// Compute icon size

   XtVaGetValues (_base, XmNwidth, &iconWidth, XmNheight, &iconHeight, NULL);
         
// Draw the shadow

   _drawShadows (0, 0, iconWidth, iconHeight, 2);

// Figure out the icon string

   const char *iconName = (_iconName != 0) ? _iconName : (_win->title ( ) != 0) ?
      _win->title ( ) : _win->name ( );
         
   const int fontX = 3;
   const int fontY = 3;
   
   if ((iconName != 0) && (iconName[0] != '\0'))
   {
      int   textWidth;
      int   len = strlen (iconName);
         
// Compute the text size

      textWidth = XTextWidth (_iconFont, iconName, len);

// Center the text in the bottom of the icon (or left-justify it)
      
      int   x, y;

      if (textWidth <= (iconWidth - (fontX * 2)))
         x = (iconWidth - (int)textWidth) / 2;
      else
         x = fontX;
           
      y = (int)iconHeight - _iconFont->descent - fontY;

// Draw the string

      XDrawString (XtDisplay (_base), XtWindow (_base), _fontGC,
         x, y, iconName, len);
   }

// Compute label size

   int labelHeight = _iconFont->descent + _iconFont->ascent + (fontY * 2);
   
   if (labelHeight >= (iconHeight - 6))
      return;
      
// Draw the separator

   int sepY = (iconHeight) - labelHeight;

   _drawLine (1, sepY, iconWidth - 2, sepY, _bottomShadowGC);
   _drawLine (1, sepY + 1, iconWidth - 2, sepY + 1, _topShadowGC);

// Draw the pixmap frame

   const int frameX = 4;
   const int frameY = 4;
   
   if ((frameX + 6) >= sepY)
      return;
      
   int   frameWidth = iconWidth - (frameX * 2);
   int   frameHeight = sepY - frameY - 2;
   
   _drawShadows (frameX, frameY, frameWidth, frameHeight, 1, True);

   frameWidth -= 2;
   frameHeight -= 2;
   
   _drawShadows (frameX + 1, frameY + 1, frameWidth, frameHeight, 1);
   
   frameWidth -= 2;
   frameHeight -= 2;

// Blit the pixmap

   if (_pixmap != 0)
   {
      if ((frameWidth > 0) && (frameHeight > 0))
      {
         int   origX, origY;
         int   drawW, drawH;
         
// Center the pixmap or top-left orient it

         if (frameWidth > _width)
         {
            origX = (frameWidth - _width) / 2;
            origX += frameX + 2;
            drawW = _width;
         }
         else
         {
            origX = frameX + 2;
            drawW = frameWidth;
         }
            
         if (frameHeight > _height)
         {
            origY = (frameHeight - _height) / 2;
            origY += frameY + 2;
            drawH = _height;
         }
         else
         {
            origY = frameY + 2;
            drawH = frameHeight;
         }
      
         XCopyArea (XtDisplay (_base), _pixmap, XtWindow (_base), _pixmapGC,
            0, 0, drawW, drawH, origX, origY);
      }
   }
}
   
// _map

void _XsMotifIcon::_map ( )
{
   unsigned long valuemask;
   XGCValues   values;
   Pixel fg;
   Pixel bg;
   int   depth;
   
// Call the base-class
      
   _XsMotifComponent::_map ( );
	 
// Get the icon pixels

   XtVaGetValues (_win->base ( ), XmNdepth, &depth, XmNbackground, &bg,
      XmNforeground, &fg, NULL);
      
// Create the default icon pixmap

   if (_pixmap == 0)
   {
      _pixmap = XCreatePixmapFromBitmapData (XtDisplay (_base), XtWindow (_base),
         xs_motif_icon_bits, xs_motif_icon_width, xs_motif_icon_height,
         fg, bg, depth);

// Set this pixmap

      setPixmap (_pixmap);
      
      _freePixmap = True;
      
// Create the icon pixmap graphics context

      valuemask = GCGraphicsExposures | GCForeground | GCBackground;
      
      values.graphics_exposures = False;
      values.foreground = fg;
      values.background = bg;

      _pixmapGC = XtGetGC (_base, valuemask, &values);
   }

// Create the font graphics context

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -