GInput::GInput(GViewI *parent, const char *InitStr, const char *Msg, const char *Title, bool Password, GInputCallback callback, void *callbackparam) { Callback = callback; CallbackParam = callbackparam; GText *Txt = new GText(-1, 5, 5, -1, -1, Msg); GDisplayString MsgDs(SysFont, ValidStr(InitStr)?InitStr:"A"); int Dx = LgiApp->GetMetric(LGI_MET_DECOR_X) + 10; int Dy = LgiApp->GetMetric(LGI_MET_DECOR_Y); int ContextX = 400; ContextX = max(ContextX, MsgDs.X() + 40); ContextX = min(ContextX, (int)(GdcD->X() * 0.8)); int EditX = ContextX; int CallbackX = callback ? GBUTTON_MIN_X + 20 : 0; ContextX = max(ContextX, Txt->X() + CallbackX); GRect r(0, 0, ContextX + CallbackX + Dx, 70 + Txt->Y() + Dy); SetParent(parent); Name(Title); SetPos(r); MoveToCenter(); GRect c = GetClient(); Children.Insert(Txt); Children.Insert(Edit = new GEdit(IDC_EDIT, 5, Txt->GetPos().y2 + 5, EditX - 1, MsgDs.Y()+7, InitStr)); if (Edit) { Edit->Password(Password); Edit->Focus(true); if (Callback) { GRect e = Edit->GetPos(); Children.Insert(new GButton(IDC_CALLBACK, c.X() - (CallbackX-5) - 6, e.y1, CallbackX-5, e.Y()-1, "...")); } } GButton *Ok = new GButton(IDOK, 0, 0, -1, -1, LgiLoadString(L_BTN_OK, "Ok")); GButton *Cancel = new GButton(IDCANCEL, 0, 0, -1, -1, LgiLoadString(L_BTN_CANCEL, "Cancel")); int BtnX = max(Ok->X(), Cancel->X()); int BtnY = Edit->GetPos().y2 + 11; GRect p = Cancel->GetPos(); p.x2 = p.x1 + BtnX - 1; p.Offset(c.X() - Cancel->X() - 5, BtnY); Cancel->SetPos(p); p = Ok->GetPos(); p.x2 = p.x1 + BtnX - 1; p.Offset(Cancel->GetPos().x1 - p.X() - 5, BtnY); Ok->SetPos(p); Children.Insert(Ok); Children.Insert(Cancel); Ok->Default(true); }
int GDialog::DoModal(OsView OverideParent) { d->ModalStatus = 0; if (Wnd && Attach(0)) { GWindow *Owner = GetParent() ? GetParent()->GetWindow() : 0; if (Owner) { GRect Pr = Owner->GetPos(); GRect Mr = GetPos(); Mr.Offset( Pr.x1 + (Pr.X() - Mr.X()) / 2 - Mr.x1, Pr.y1 + (Pr.Y() - Mr.Y()) / 2 - Mr.y1); SetPos(Mr); Owner->SetChildDialog(this); } d->IsModal = true; AttachChildren(); Visible(true); RunAppModalLoopForWindow(Wnd); if (Owner) Owner->SetChildDialog(0); } return d->ModalStatus; }
void GPaneThrottle::OnPaint(GSurface *pDC) { GRect r(0, 0, X()-1, Y()-1); int x, y; pDC->GetOrigin(x, y); LgiThinBorder(pDC, r, DefaultSunkenEdge); pDC->Colour(LC_MED, 24); pDC->Rectangle(r.x1, r.y1, r.x1+THROTTLE_TEXT_WIDTH, r.y2); if (Slider) { GRect Sr = r; #ifdef WIN32 Sr.Offset(GetPos().x1, GetPos().y1); #endif Sr.x1 += THROTTLE_TEXT_WIDTH+1; Slider->SetPos(Sr); if (!Slider->IsAttached()) { #ifdef WIN32 Slider->Attach(GetParent()); #else Slider->Attach(this); #endif Slider->SetNotify(this); Slider->SetLimits(0, 100); Slider->Value(100); if (Pipe < 0) { GVariant v; if (App->GetValue(OPT_PipeSize, v)) Pipe = v.CastInt32(); if (Slider) { v = 100; if (App->GetValue(OPT_Throttle, v)) Slider->Value(v.CastInt32()); } } // DumpHnd(HIViewGetRoot(GetWindow()->WindowHandle())); } char Str[256]; int64 v = Value(); if (v < 100) { if (PipeSize[Pipe] < (1 << 20)) { sprintf(Str, "%i%% of %i Kbps", (int)v, PipeSize[Pipe]>>10); } else { sprintf(Str, "%i%% of %.1f Mbps", (int)v, (double)(PipeSize[Pipe]>>20)); } }
void GColourSelect::OnPaint(GSurface *pDC) { GDropDown::OnPaint(pDC); GRect r = GetClient(); r.x2 -= 14; r.Size(5, 5); if (IsOpen()) r.Offset(1, 1); bool HasColour = Enabled() && c32 != 0; pDC->Colour(HasColour ? LC_BLACK : LC_LOW, 24); pDC->Box(&r); r.Size(1, 1); pDC->Colour(HasColour ? c32 : Rgb24To32(LC_LOW), 32); if (HasColour) { pDC->Rectangle(&r); } else { pDC->Line(r.x1, r.y1, r.x2, r.y2); pDC->Line(r.x1, r.y2, r.x2, r.y1); } }
GAlert::GAlert( GViewI *parent, const char *Title, const char *Text, const char *Btn1, const char *Btn2, const char *Btn3) { GText *t = 0; Children.Insert(t = new GText(-1, 8, 8, -1, -1, (char*)Text)); if (t) { // Setup dialog SetParent(parent); Name((char*)Title); List<GButton> Btns; List<const char> Names; if (Btn1) Names.Insert(Btn1); if (Btn2) Names.Insert(Btn2); if (Btn3) Names.Insert(Btn3); int i = 1, Tx = 0; for (const char *n=Names.First(); n; n=Names.Next()) { GDisplayString ds(SysFont, (char*)n); int x = ds.X(); GButton *v; Btns.Insert(v = new GButton(CMD_BASE + i++, 0, 0, (int) ((30.0f + x) * BTN_SCALE), (int) (20.0f * BTN_SCALE), (char*)n)); Tx += v->X() + ((i>1) ? 10 : 0); } int x = LgiApp->GetMetric(LGI_MET_DECOR_X) + 16; int y = LgiApp->GetMetric(LGI_MET_DECOR_Y) + 20 + 8 + 16; GRect r; if (t) { x += max(Tx, t->X()); y += t->Y(); r.ZOff(x, y); } SetPos(r); MoveToCenter(); // Setup controls int Cx = X() / 2; int Bx = Cx - (Tx / 2); for (GButton *b=Btns.First(); b; b=Btns.Next()) { GRect r; r.ZOff(b->X()-1, b->Y()-1); r.Offset(Bx, t->GetPos().y2 + 8); b->SetPos(r); Children.Insert(b); Bx += b->X() + 10; } } }
void GScreenDC::SetClient(GRect *r) { // Unset previous client if (d->Client.Valid()) { d->View->SetOrigin(0, 0); d->View->ConstrainClippingRegion(NULL); } if (r) { d->Client = *r; } else { d->Client.ZOff(-1, -1); } // Set new client if (d->Client.Valid()) { GRect b = d->Client; b.Offset(-b.x1, -b.y1); BRegion r(b); d->View->ConstrainClippingRegion(&r); d->View->SetOrigin(d->Client.x1, d->Client.y1); } }
bool GView::Invalidate(GRect *r, bool Repaint, bool Frame) { if (IsAttached()) { if (InThread() && !d->InPaint) { GRect Client; if (Frame) Client.ZOff(Pos.X()-1, Pos.Y()-1); else Client = GView::GetClient(false); static bool Repainting = false; if (!Repainting) { Repainting = true; GdkWindow *hnd = gtk_widget_get_window(_View); if (hnd) { if (r) { GRect cr = *r; cr.Offset(Client.x1, Client.y1); Gtk::GdkRectangle r = cr; gdk_window_invalidate_rect(hnd, &r, FALSE); } else { Gtk::GdkRectangle r = {0, 0, Pos.X(), Pos.Y()}; gdk_window_invalidate_rect(hnd, &r, FALSE); } } Repainting = false; } } else { X11_INVALIDATE_PARAMS *p = new X11_INVALIDATE_PARAMS; if (p) { if (r) { p->Rgn = *r; } else { p->Rgn.ZOff(-1, -1); } p->Repaint = Repaint; p->View = this; PostEvent(M_X11_INVALIDATE, (GMessage::Param)p, 0); } } return true; } else { GRect Up; GViewI *p = this; if (r) { Up = *r; } else { Up.Set(0, 0, Pos.X()-1, Pos.Y()-1); } while (p && !p->IsAttached()) { GRect pos = p->GetPos(); Up.Offset(pos.x1, pos.y1); p = p->GetParent(); } if (p && p->IsAttached()) { return p->Invalidate(&Up, Repaint); } } return false; }