summaryrefslogtreecommitdiffstats
path: root/ksirc/puke/pbutton.cpp
blob: f21cdf03190d37fb1e2a34f9beeecfcf401b7e7c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
#include <stdio.h>


#include <tqpixmap.h>

#include <kdebug.h>

#include "pbutton.h"

PObject *
PButton::createWidget(CreateArgs &ca)
{
  PButton *pb = new PButton(ca.parent);
  TQButton *qb;
  if(ca.parent != 0 && ca.parent->widget()->isWidgetType() == TRUE)
    qb = new TQButton((TQWidget *) ca.parent->widget());
  else
    qb = new TQButton();
  pb->setWidget(qb);
  pb->setWidgetId(ca.pwI);
  return pb;
}


PButton::PButton(PObject *parent)
  : PWidget(parent)
{
  //  kdDebug(5008) << "PLineEdit PLineEdit called" << endl;
  button = 0;
  setWidget(0);
}

PButton::~PButton()
{
  //  kdDebug(5008) << "PLineEdit: in destructor" << endl;
  /*
  delete widget();     // Delete the frame
  button=0;          // Set it to 0
  setWidget(button); // Now set all widget() calls to 0.
  */
}

void PButton::messageHandler(int fd, PukeMessage *pm)
{
  PukeMessage pmRet;
  switch(pm->iCommand){
    case PUKE_BUTTON_SET_TEXT:
    if(checkWidget() == FALSE)
      return;

    widget()->setText(pm->cArg);    // set the text

    pmRet.iCommand = - pm->iCommand;// Create ack
    pmRet.iWinId = pm->iWinId;
    pmRet.cArg = (char*) widget()->text().ascii(); // It's const, but we don't mess with it anyways
    pmRet.iTextSize = strlen(pmRet.cArg);
    emit outputMessage(fd, &pmRet);
    break;
  case PUKE_BUTTON_SET_PIXMAP:
    if(checkWidget() == FALSE)
      return;
    
    widget()->setPixmap(TQPixmap(pm->cArg));

    pmRet.iCommand = - pm->iCommand;
    pmRet.iWinId = pm->iWinId;
    pmRet.iArg = widget()->pixmap()->isNull();
    pmRet.cArg = 0;
    emit outputMessage(fd, &pmRet);
    break;
  case PUKE_BUTTON_SET_AUTORESIZE:
    if(checkWidget() == FALSE)
      return;

    pmRet.iCommand = - pm->iCommand;
    pmRet.iWinId = - pm->iWinId;
    pmRet.cArg = 0;
    emit outputMessage(fd, &pmRet);
    break;
  default:
    PWidget::messageHandler(fd, pm);
  }
}

void PButton::setWidget(TQObject *_qb)
{
  if(_qb != 0 && _qb->inherits(TQBUTTON_OBJECT_NAME_STRING) == FALSE)
  {
    errorInvalidSet(_qb);
    return;
  }

  button = (TQButton *) _qb;
  if(button != 0){
    connect(button, TQT_SIGNAL(pressed()),
	    this, TQT_SLOT(buttonPressed()));
    connect(button, TQT_SIGNAL(released()),
	    this, TQT_SLOT(buttonReleased()));
    connect(button, TQT_SIGNAL(clicked()),
	    this, TQT_SLOT(buttonClicked()));
    connect(button, TQT_SIGNAL(toggled(bool)),
	    this, TQT_SLOT(buttonToggled(bool)));
    
  }
  PWidget::setWidget(_qb);

}


TQButton *PButton::widget()
{
  return button;
}

void PButton::buttonMessage(int iCommand)
{
  PukeMessage pmRet;

  pmRet.iCommand = iCommand;
  pmRet.iArg = 0;
  pmRet.iWinId = widgetIden().iWinId;
  pmRet.cArg = 0;

  emit outputMessage(widgetIden().fd, &pmRet);
}

void PButton::buttonPressed()
{
  buttonMessage(PUKE_BUTTON_PRESSED_ACK);
}

void PButton::buttonReleased()
{
  buttonMessage(PUKE_BUTTON_RELEASED_ACK);
}

void PButton::buttonClicked()
{
  buttonMessage(PUKE_BUTTON_CLICKED_ACK);
}

void PButton::buttonToggled(bool)
{
  buttonMessage(PUKE_BUTTON_TOGGLED_ACK);
}

bool PButton::checkWidget()
{
  if(widget() == 0){
    kdDebug(5008) << "PButton: No Widget set" << endl;
    return FALSE;
  }
  return TRUE;
}

#include "pbutton.moc"