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 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599
|
{ $Id$}
{
*****************************************************************************
* GtkWSComCtrls.pp *
* ---------------- *
* *
* *
*****************************************************************************
*****************************************************************************
* This file is part of the Lazarus Component Library (LCL)
*
* See the file COPYING.modifiedLGPL.txt, included in this distribution,
* for details about the license.
*****************************************************************************
}
unit GtkWSComCtrls;
{$mode objfpc}{$H+}
interface
uses
// libs
{$IFDEF GTK2}
GLib2, Gtk2, Gdk2,
{$ELSE}
GLib, Gtk, Gdk,
{$ENDIF}
// LCL
ComCtrls, Classes, FPCAdds, LCLType, LMessages, Controls, Graphics,
StdCtrls, LCLProc, ImgList, Math,
// widgetset
InterfaceBase, WSComCtrls, WSLCLClasses, WSProc, WSControls,
// interface
GtkDef, GtkExtra, GtkWSPrivate;
type
{ TGtkWSCustomPage }
TGtkWSCustomPage = class(TWSCustomPage)
protected
class procedure SetCallbacks(const AGtkWidget: PGtkWidget; const AWidgetInfo: PWidgetInfo); virtual;
published
class function CreateHandle(const AWinControl: TWinControl;
const AParams: TCreateParams): TLCLHandle; override;
class procedure UpdateProperties(const ACustomPage: TCustomPage); override;
class procedure SetBounds(const AWinControl: TWinControl; const ALeft, ATop, AWidth, AHeight: Integer); override;
class procedure ShowHide(const AWinControl: TWinControl); override;
end;
{ TGtkWSCustomTabControl }
TGtkWSCustomTabControl = class(TWSCustomTabControl)
protected
class procedure SetCallbacks(const AGtkWidget: PGtkWidget; const AWidgetInfo: PWidgetInfo); virtual;
published
class function CreateHandle(const AWinControl: TWinControl;
const AParams: TCreateParams): TLCLHandle; override;
class procedure AddPage(const ATabControl: TCustomTabControl;
const AChild: TCustomPage; const AIndex: integer); override;
class procedure MovePage(const ATabControl: TCustomTabControl;
const AChild: TCustomPage; const NewIndex: integer); override;
class procedure RemovePage(const ATabControl: TCustomTabControl;
const AIndex: integer); override;
class function GetCapabilities: TCTabControlCapabilities; override;
class function GetNotebookMinTabHeight(const AWinControl: TWinControl): integer; override;
class function GetNotebookMinTabWidth(const AWinControl: TWinControl): integer; override;
class function GetTabIndexAtPos(const ATabControl: TCustomTabControl; const AClientPos: TPoint): integer; override;
class function GetTabRect(const ATabControl: TCustomTabControl; const AIndex: Integer): TRect; override;
class procedure SetPageIndex(const ATabControl: TCustomTabControl; const AIndex: integer); override;
class procedure SetTabPosition(const ATabControl: TCustomTabControl; const ATabPosition: TTabPosition); override;
class procedure ShowTabs(const ATabControl: TCustomTabControl; AShowTabs: boolean); override;
class procedure UpdateProperties(const ATabControl: TCustomTabControl); override;
end;
{ TGtkWSStatusBar }
TGtkWSStatusBar = class(TWSStatusBar)
protected
class procedure SetCallbacks(const AWidget: PGtkWidget; const AWidgetInfo: PWidgetInfo); virtual;
published
class function CreateHandle(const AWinControl: TWinControl; const AParams: TCreateParams): TLCLHandle; override;
class procedure PanelUpdate(const AStatusBar: TStatusBar; PanelIndex: integer); override;
class procedure SetPanelText(const AStatusBar: TStatusBar; PanelIndex: integer); override;
class procedure Update(const AStatusBar: TStatusBar); override;
class procedure GetPreferredSize(const AWinControl: TWinControl;
var PreferredWidth, PreferredHeight: integer;
WithThemeSpace: Boolean); override;
end;
{ TGtkWSTabSheet }
TGtkWSTabSheet = class(TWSTabSheet)
published
end;
{ TGtkWSPageControl }
TGtkWSPageControl = class(TWSPageControl)
published
end;
{ TGtkWSCustomListView }
TGtkWSCustomListView = class(TWSCustomListView)
{$IFDEF GTK1}
private
class procedure ItemChangeInternal(const ACListWidget: PGtkCList; const ALV: TCustomListView; const AIndex: Integer; const AItem: TListItem);
class procedure SetPropertyInternal(const ACListWidget: PGtkCList; const AInfo: PWidgetInfo; const AProp: TListViewProperty; const AIsSet: Boolean);
protected
class procedure SetListCallbacks(const AScrollWidget, AListWidget: PGtkWidget; const AWidgetInfo: PWidgetInfo);
published
// columns
class procedure ColumnDelete(const ALV: TCustomListView; const AIndex: Integer); override;
class function ColumnGetWidth(const ALV: TCustomListView; const AIndex: Integer; const AColumn: TListColumn): Integer; override;
class procedure ColumnInsert(const ALV: TCustomListView; const AIndex: Integer; const AColumn: TListColumn); override;
class procedure ColumnMove(const ALV: TCustomListView; const AOldIndex, ANewIndex: Integer; const AColumn: TListColumn); override;
class procedure ColumnSetAlignment(const ALV: TCustomListView; const AIndex: Integer; const AColumn: TListColumn; const AAlignment: TAlignment); override;
class procedure ColumnSetAutoSize(const ALV: TCustomListView; const AIndex: Integer; const AColumn: TListColumn; const AAutoSize: Boolean); override;
class procedure ColumnSetCaption(const ALV: TCustomListView; const AIndex: Integer; const AColumn: TListColumn; const ACaption: String); override;
class procedure ColumnSetImage(const ALV: TCustomListView; const AIndex: Integer; const AColumn: TListColumn; const AImageIndex: Integer); override;
class procedure ColumnSetMaxWidth(const ALV: TCustomListView; const AIndex: Integer; const AColumn: TListColumn; const AMaxWidth: Integer); override;
class procedure ColumnSetMinWidth(const ALV: TCustomListView; const AIndex: Integer; const AColumn: TListColumn; const AMinWidth: integer); override;
class procedure ColumnSetWidth(const ALV: TCustomListView; const AIndex: Integer; const AColumn: TListColumn; const AWidth: Integer); override;
class procedure ColumnSetVisible(const ALV: TCustomListView; const AIndex: Integer; const AColumn: TListColumn; const AVisible: Boolean); override;
// items
class procedure ItemDelete(const ALV: TCustomListView; const AIndex: Integer); override;
class procedure ItemExchange(const ALV: TCustomListView; AItem: TListItem; const AIndex1, AIndex2: Integer); override;
class procedure ItemMove(const ALV: TCustomListView; AItem: TListItem; const AFromIndex, AToIndex: Integer); override;
class function ItemGetState(const ALV: TCustomListView; const AIndex: Integer; const AItem: TListItem; const AState: TListItemState; out AIsSet: Boolean): Boolean; override; // returns True if supported
class procedure ItemInsert(const ALV: TCustomListView; const AIndex: Integer; const AItem: TListItem); override;
class procedure ItemSetImage(const ALV: TCustomListView; const AIndex: Integer; const AItem: TListItem; const ASubIndex, AImageIndex: Integer); override;
class procedure ItemSetState(const ALV: TCustomListView; const AIndex: Integer; const AItem: TListItem; const AState: TListItemState; const AIsSet: Boolean); override;
class procedure ItemSetText(const ALV: TCustomListView; const AIndex: Integer; const AItem: TListItem; const ASubIndex: Integer; const AText: String); override;
class procedure ItemShow(const ALV: TCustomListView; const AIndex: Integer; const AItem: TListItem; const PartialOK: Boolean); override;
// lv
class function CreateHandle(const AWinControl: TWinControl; const AParams: TCreateParams): HWND; override;
class procedure BeginUpdate(const ALV: TCustomListView); override;
class procedure EndUpdate(const ALV: TCustomListView); override;
class function GetBoundingRect(const ALV: TCustomListView): TRect; override;
class function GetDropTarget(const ALV: TCustomListView): Integer; override;
class function GetFocused(const ALV: TCustomListView): Integer; override;
class function GetHoverTime(const ALV: TCustomListView): Integer; override;
class function GetItemAt(const ALV: TCustomListView; x,y: integer): Integer; override;
class function GetSelCount(const ALV: TCustomListView): Integer; override;
class function GetSelection(const ALV: TCustomListView): Integer; override;
class function GetTopItem(const ALV: TCustomListView): Integer; override;
class function GetViewOrigin(const ALV: TCustomListView): TPoint; override;
class function GetVisibleRowCount(const ALV: TCustomListView): Integer; override;
class procedure SetAllocBy(const ALV: TCustomListView; const AValue: Integer); override;
class procedure SetDefaultItemHeight(const ALV: TCustomListView; const AValue: Integer); override;
class procedure SetHotTrackStyles(const ALV: TCustomListView; const AValue: TListHotTrackStyles); override;
class procedure SetHoverTime(const ALV: TCustomListView; const AValue: Integer); override;
// class procedure SetIconOptions(const ALV: TCustomListView; const AValue: TIconOptions); override;
class procedure SetImageList(const ALV: TCustomListView; const AList: TListViewImageList; const AValue: TCustomImageListResolution); override;
class procedure SetProperty(const ALV: TCustomListView; const AProp: TListViewProperty; const AIsSet: Boolean); override;
class procedure SetProperties(const ALV: TCustomListView; const AProps: TListViewProperties); override;
class procedure SetScrollBars(const ALV: TCustomListView; const AValue: TScrollStyle); override;
class procedure SetSort(const ALV: TCustomListView; const AType: TSortType; const AColumn: Integer;
const ASortDirection: TSortDirection); override;
class procedure SetViewOrigin(const ALV: TCustomListView; const AValue: TPoint); override;
class procedure SetViewStyle(const ALV: TCustomListView; const Avalue: TViewStyle); override;
{$ENDIF}
end;
{ TGtkWSListView }
TGtkWSListView = class(TWSListView)
published
end;
{ TGtkWSProgressBar }
{$IFDEF GTK1}
TGtkWSProgressBar = class(TWSProgressBar)
private
protected
class procedure SetCallbacks(const AWidget: PGtkWidget; const AWidgetInfo: PWidgetInfo); virtual;
published
class function CreateHandle(const AWinControl: TWinControl; const AParams: TCreateParams): TLCLHandle; override;
class procedure ApplyChanges(const AProgressBar: TCustomProgressBar); override;
class procedure SetPosition(const AProgressBar: TCustomProgressBar; const NewPosition: integer); override;
end;
{$ENDIF}
{ TGtkWSCustomUpDown }
TGtkWSCustomUpDown = class(TWSCustomUpDown)
published
end;
{ TGtkWSUpDown }
TGtkWSUpDown = class(TWSUpDown)
published
end;
{ TGtkWSToolButton }
TGtkWSToolButton = class(TWSToolButton)
published
end;
{ TGtkWSToolBar }
TGtkWSToolBar = class(TWSToolBar)
protected
class procedure SetCallbacks(const AWidget: PGtkWidget; const AWidgetInfo: PWidgetInfo); virtual;
published
class function CreateHandle(const AWinControl: TWinControl; const AParams: TCreateParams): TLCLHandle; override;
{$ifdef OldToolbar}
class function GetButtonCount(const AToolBar: TToolBar): integer; override;
class procedure InsertToolButton(const AToolBar: TToolbar; const AControl: TControl); override;
class procedure DeleteToolButton(const AToolBar: TToolbar; const AControl: TControl); override;
{$endif}
end;
{ TGtkWSTrackBar }
TGtkWSTrackBar = class(TWSTrackBar)
protected
class procedure SetCallbacks(const AWidget: PGtkWidget; const AWidgetInfo: PWidgetInfo); virtual;
published
class function CreateHandle(const AWinControl: TWinControl; const AParams: TCreateParams): TLCLHandle; override;
class procedure ApplyChanges(const ATrackBar: TCustomTrackBar); override;
class function GetPosition(const ATrackBar: TCustomTrackBar): integer; override;
class procedure SetPosition(const ATrackBar: TCustomTrackBar; const NewPosition: integer); override;
end;
{ TGtkWSCustomTreeView }
TGtkWSCustomTreeView = class(TWSCustomTreeView)
published
end;
{ TGtkWSTreeView }
TGtkWSTreeView = class(TWSTreeView)
published
end;
implementation
uses
SysUtils, LazUtilities,
GtkProc, GtkInt, GtkGlobals,
GtkWSControls;
const
DEFAULT_IMAGE_SPACING = 3;
{$include gtkpagecontrol.inc}
{$IFDEF GTK1}
{$I gtkwscustomlistview.inc }
{$ENDIF}
{ TGtkWSProgressBar }
{$IFDEF GTK1}
class procedure TGtkWSProgressBar.SetCallbacks(const AWidget: PGtkWidget;
const AWidgetInfo: PWidgetInfo);
begin
TGtkWSWinControl.SetCallbacks(PGtkObject(AWidget), TComponent(AWidgetInfo^.LCLObject));
end;
class function TGtkWSProgressBar.CreateHandle(const AWinControl: TWinControl;
const AParams: TCreateParams): TLCLHandle;
var
Adjustment: PGtkAdjustment;
Widget: PGtkWidget;
WidgetInfo: PWidgetInfo;
begin
with TCustomProgressBar(AWinControl) do
begin
// Create a GtkAdjustment object to hold the range of the progress bar
Adjustment := PGtkAdjustment(gtk_adjustment_new(Position, Min, Max, 0, 0, 0));
// Create the GtkProgressBar using the adjustment
Widget := gtk_progress_bar_new_with_adjustment(Adjustment);
end;
Result := TLCLHandle(PtrUInt(Widget));
{$IFDEF DebugLCLComponents}
DebugGtkWidgets.MarkCreated(Widget, dbgsName(AWinControl));
{$ENDIF}
WidgetInfo := CreateWidgetInfo(Pointer(Result), AWinControl, AParams);
Set_RC_Name(AWinControl, Widget);
SetCallbacks(Widget, WidgetInfo);
end;
class procedure TGtkWSProgressBar.ApplyChanges(const AProgressBar: TCustomProgressBar);
var
wHandle: HWND;
begin
wHandle := AProgressBar.Handle;
with AProgressBar do
begin
if Smooth
then gtk_progress_bar_set_bar_style (GTK_PROGRESS_BAR(Pointer(Pointer(wHandle))),
GTK_PROGRESS_CONTINUOUS)
else gtk_progress_bar_set_bar_style (GTK_PROGRESS_BAR(Pointer(Pointer(wHandle))),
GTK_PROGRESS_DISCRETE);
case Orientation of
pbVertical : gtk_progress_bar_set_orientation(
GTK_PROGRESS_BAR(Pointer(Pointer(wHandle))),
GTK_PROGRESS_BOTTOM_TO_TOP);
pbRightToLeft: gtk_progress_bar_set_orientation(
GTK_PROGRESS_BAR(Pointer(Pointer(wHandle))),
GTK_PROGRESS_RIGHT_TO_LEFT);
pbTopDown : gtk_progress_bar_set_orientation(
GTK_PROGRESS_BAR(Pointer(Pointer(wHandle))),
GTK_PROGRESS_TOP_TO_BOTTOM);
else { pbHorizontal is default }
gtk_progress_bar_set_orientation(GTK_PROGRESS_BAR(Pointer(Pointer(wHandle))),
GTK_PROGRESS_LEFT_TO_RIGHT);
end;
if BarShowText then
begin
gtk_progress_set_format_string (GTK_PROGRESS(Pointer(Pointer(wHandle))),
'%v from [%l-%u] (=%p%%)');
gtk_progress_set_show_text (GTK_PROGRESS(Pointer(Pointer(wHandle))), GdkTrue);
end
else
gtk_progress_set_show_text (GTK_PROGRESS(Pointer(Pointer(wHandle))), GDKFalse);
gtk_progress_configure(GTK_PROGRESS(Pointer(Pointer(wHandle))),Position,Min,Max);
end;
end;
class procedure TGtkWSProgressBar.SetPosition(const AProgressBar: TCustomProgressBar; const NewPosition: integer);
begin
gtk_progress_set_value(GTK_PROGRESS(Pointer(AProgressBar.Handle)), NewPosition);
end;
{$ENDIF GTK1}
{ TGtkWSToolbar }
{$ifdef OldToolbar}
function TGtkWSToolbar.GetButtonCount(const AToolBar: TToolBar): integer;
begin
Result := PGtkToolbar(AToolbar.Handle)^.num_Children;
end;
procedure TGtkWSToolbar.InsertToolButton(const AToolBar: TToolbar; const AControl: TControl);
var
Num : Integer; // currently only used for LM_INSERTTOOLBUTTON and LM_ADDITEM
pStr : PChar;
pStr2 : PChar; // currently only used for LM_INSERTTOOLBUTTON
handle: HWND;
begin
if (AControl is TToolbutton) then
begin
pStr := StrAlloc(Length(TToolbutton(AControl).Caption)+1);
handle := TToolButton(AControl).Handle;
try
StrPCopy(pStr,TToolbutton(AControl).Caption);
pStr2 := StrAlloc(Length(TControl(AControl).Hint)+1);
finally
StrPCopy(pStr2,TControl(AControl).Hint);
end;
end
else Begin
RaiseException('Can not assign this control to the toolbar');
exit;
end;
num := TToolbar(TWinControl(AControl).parent).Buttonlist.IndexOf(TControl(AControl));
if num < 0 then Num := TToolbar(TWinControl(AControl).parent).Buttonlist.Count+1;
//DebugLn(Format('Trace:NUM = %d in INSERTBUTTON',[num]));
gtk_toolbar_insert_widget(pGTKToolbar(TWinControl(AControl).parent.Handle),
pgtkwidget(handle),pstr,pStr2,Num);
StrDispose(pStr);
StrDispose(pStr2);
end;
procedure TGtkWSToolbar.DeleteToolButton(const AToolBar: TToolbar; const AControl: TControl);
begin
with pgtkToolbar(TToolbar(TWinControl(AControl).parent).handle)^ do
children := g_list_remove(pgList(children), AControl);
// Next 3 lines: should be same as above, remove when above lines are proofed
// pgtkToolbar(TToolbar(TWinControl(AControl).parent).handle)^.children :=
// g_list_remove(pgList(pgtkToolbar(TToolbar(TWinControl(AControl).parent).handle)^.children),
// AControl);
end;
{$endif}
{ TGtkWSTrackBar }
class procedure TGtkWSTrackBar.SetCallbacks(const AWidget: PGtkWidget;
const AWidgetInfo: PWidgetInfo);
begin
TGtkWSWinControl.SetCallbacks(PGtkObject(AWidget), TComponent(AWidgetInfo^.LCLObject));
TGtkWidgetset(WidgetSet).SetCallback(LM_CHANGED, PGtkObject(AWidget), AWidgetInfo^.LCLObject);
end;
class function TGtkWSTrackBar.CreateHandle(const AWinControl: TWinControl;
const AParams: TCreateParams): TLCLHandle;
var
Adjustment: PGtkAdjustment;
Widget: PGtkWidget;
WidgetInfo: PWidgetInfo;
begin
with TCustomTrackBar(AWinControl) do
begin
Adjustment := PGtkAdjustment(gtk_adjustment_new (Position, Min, Max,
linesize, pagesize, 0));
if (Orientation = trHorizontal) then
Widget := gtk_hscale_new(Adjustment)
else
Widget := gtk_vscale_new(Adjustment);
gtk_scale_set_digits(PGtkScale(Widget), 0);
end;
Result := TLCLHandle(PtrUInt(Widget));
{$IFDEF DebugLCLComponents}
DebugGtkWidgets.MarkCreated(Widget, dbgsName(AWinControl));
{$ENDIF}
WidgetInfo := CreateWidgetInfo(Pointer(Result), AWinControl, AParams);
Set_RC_Name(AWinControl, Widget);
SetCallbacks(Widget, WidgetInfo);
end;
class procedure TGtkWSTrackBar.ApplyChanges(const ATrackBar: TCustomTrackBar);
var
wHandle: HWND;
Adjustment: PGtkAdjustment;
begin
with ATrackBar do
begin
wHandle := Handle;
Adjustment := gtk_range_get_adjustment (GTK_RANGE(Pointer(wHandle)));
Adjustment^.lower := Min;
Adjustment^.Upper := Max;
Adjustment^.Value := Position;
Adjustment^.step_increment := LineSize;
Adjustment^.page_increment := PageSize;
{ now do some of the more sophisticated features }
{ Hint: For some unknown reason we have to disable the draw_value first,
otherwise it's set always to true }
gtk_scale_set_draw_value (GTK_SCALE (Pointer(wHandle)), false);
if (TickStyle<>tsNone) then
begin
gtk_scale_set_draw_value (GTK_SCALE (Pointer(wHandle)), true);
case ScalePos of
trLeft : gtk_scale_set_value_pos (GTK_SCALE (Pointer(wHandle)), GTK_POS_LEFT);
trRight : gtk_scale_set_value_pos (GTK_SCALE (Pointer(wHandle)), GTK_POS_RIGHT);
trTop : gtk_scale_set_value_pos (GTK_SCALE (Pointer(wHandle)), GTK_POS_TOP);
trBottom: gtk_scale_set_value_pos (GTK_SCALE (Pointer(wHandle)), GTK_POS_BOTTOM);
end;
end;
//Not here (Delphi compatibility): gtk_signal_emit_by_name (GTK_Object (Adjustment), 'value_changed');
end;
end;
class function TGtkWSTrackBar.GetPosition(const ATrackBar: TCustomTrackBar): integer;
begin
if ATrackBar.HandleAllocated then
begin
Result := RoundToInt(gtk_range_get_adjustment(
GTK_RANGE(Pointer(ATrackBar.Handle)))^.value);
end else
Result := 0;
end;
class procedure TGtkWSTrackBar.SetPosition(const ATrackBar: TCustomTrackBar; const NewPosition: integer);
var
Handle: HWND;
begin
Handle := ATrackBar.Handle;
gtk_range_get_adjustment(GTK_RANGE(Pointer(Handle)))^.value := NewPosition;
g_signal_emit_by_name(PGtkObject(
gtk_range_get_adjustment(GTK_RANGE(Pointer(Handle)))), 'value_changed');
end;
{ TGtkWSStatusBar }
class procedure TGtkWSStatusBar.SetCallbacks(const AWidget: PGtkWidget;
const AWidgetInfo: PWidgetInfo);
begin
TGtkWSWinControl.SetCallbacks(PGtkObject(AWidget), TComponent(AWidgetInfo^.LCLObject));
end;
class function TGtkWSStatusBar.CreateHandle(const AWinControl: TWinControl;
const AParams: TCreateParams): TLCLHandle;
var
Widget: PGtkWidget;
WidgetInfo: PWidgetInfo;
begin
Widget := gtk_hbox_new(false,0);
UpdateStatusBarPanels(AWinControl, Widget);
Result := TLCLHandle(PtrUInt(Widget));
{$IFDEF DebugLCLComponents}
DebugGtkWidgets.MarkCreated(Widget, dbgsName(AWinControl));
{$ENDIF}
WidgetInfo := CreateWidgetInfo(Pointer(Result), AWinControl, AParams);
Set_RC_Name(AWinControl, Widget);
SetCallbacks(Widget, WidgetInfo);
end;
class procedure TGtkWSStatusBar.PanelUpdate(const AStatusBar: TStatusBar;
PanelIndex: integer);
var
HBox: PGtkWidget;
StatusPanelWidget: PGtkWidget;
BoxChild: PGtkBoxChild;
begin
//DebugLn('TGtkWidgetSet.StatusBarPanelUpdate ',DbgS(AStatusBar),' PanelIndex=',dbgs(PanelIndex));
if PanelIndex>=0 then begin
// update one
HBox:=PGtkWidget(AStatusBar.Handle);
BoxChild:=PGtkBoxChild(g_list_nth_data(PGtkBox(HBox)^.children,PanelIndex));
if BoxChild=nil then
RaiseGDBException('TGtkWidgetSet.StatusBarPanelUpdate Index out of bounds');
StatusPanelWidget:=BoxChild^.Widget;
UpdateStatusBarPanel(AStatusBar,PanelIndex,StatusPanelWidget);
end else begin
// update all
UpdateStatusBarPanels(AStatusBar,PGtkWidget(AStatusBar.Handle));
end;
end;
class procedure TGtkWSStatusBar.SetPanelText(const AStatusBar: TStatusBar;
PanelIndex: integer);
begin
PanelUpdate(AStatusBar,PanelIndex);
end;
class procedure TGtkWSStatusBar.Update(const AStatusBar: TStatusBar);
begin
//DebugLn('TGtkWidgetSet.StatusBarUpdate ',DbgS(AStatusBar));
UpdateStatusBarPanels(AStatusBar,PGtkWidget(AStatusBar.Handle));
end;
class procedure TGtkWSStatusBar.GetPreferredSize(const AWinControl: TWinControl;
var PreferredWidth, PreferredHeight: integer; WithThemeSpace: Boolean);
var
StatusBarWidget: PGtkWidget;
Requisition: TGtkRequisition;
begin
StatusBarWidget:=GetStyleWidget(lgsStatusBar);
// set size to default
gtk_widget_set_usize(StatusBarWidget,-1,-1);
// ask default size
gtk_widget_size_request(StatusBarWidget,@Requisition);
PreferredHeight:=Requisition.height;
//debugln('TGtkWSStatusBar.GetPreferredSize END ',dbgs(PreferredHeight));
end;
{ TGtkWSToolBar }
class procedure TGtkWSToolBar.SetCallbacks(const AWidget: PGtkWidget;
const AWidgetInfo: PWidgetInfo);
begin
TGtkWSWinControl.SetCallbacks(PGtkObject(AWidget), TComponent(AWidgetInfo^.LCLObject));
end;
class function TGtkWSToolBar.CreateHandle(const AWinControl: TWinControl;
const AParams: TCreateParams): TLCLHandle;
var
Widget, ClientWidget: PGtkWidget;
WidgetInfo: PWidgetInfo;
begin
{$ifdef gtk1}
Widget := gtk_toolbar_new();
gtk_toolbar_set_space_size(PGTKToolbar(Widget), 0);
gtk_toolbar_set_space_style(PGTKToolbar(Widget), GTK_TOOLBAR_SPACE_EMPTY);
ClientWidget := gtk_fixed_new();
gtk_toolbar_insert_widget(PGTKToolbar(Widget), ClientWidget, nil, nil, 0);
{$else}
Widget:= gtk_hbox_new(false,0);
ClientWidget := CreateFixedClientWidget;
gtk_container_add(GTK_CONTAINER(Widget), ClientWidget);
{$endif}
Result := TLCLHandle(PtrUInt(Widget));
WidgetInfo := CreateWidgetInfo(Widget, AWinControl, AParams);
{$IFDEF DebugLCLComponents}
DebugGtkWidgets.MarkCreated(Widget, dbgsName(AWinControl));
{$ENDIF}
gtk_widget_show(ClientWidget);
SetFixedWidget(Widget, ClientWidget);
SetMainWidget(Widget, ClientWidget);
gtk_widget_show(Widget);
Set_RC_Name(AWinControl, Widget);
SetCallbacks(Widget, WidgetInfo);
end;
end.
|